Raf*_*res 18 yacc objective-c ios
我正在尝试使用YACC和xcode,这是本机支持的,为此我发现这个样本工作得很好.我的想法是建立自己的语法,所以我开始尝试项目,看它是否会支持我需要的东西.因此,我创建了以下界面:
.H
#import <Foundation/Foundation.h>
@interface HYPLangNodeNP : NSObject
@end
Run Code Online (Sandbox Code Playgroud)
.M
#import "HYPLangNodeNP.h"
@implementation HYPLangNodeNP
@end
Run Code Online (Sandbox Code Playgroud)
是的,这只是一个空实现.然后我只对语法做了两处修改:
1)添加HYPLangNodeNP导入
%{
#import "MessageBlocks.h"
#import "HYPLangNodeNP.h"
int yylex(void);
void yyerror(char *s);
%}
Run Code Online (Sandbox Code Playgroud)
2)将HYPLangNodeNP添加到类型%union
%union {
float value;
NSString *identifier;
HYPLangNodeNP *node;
}
Run Code Online (Sandbox Code Playgroud)
该项目无法编译Unknown type name 'HYPLangNodeNP'.有谁知道如何解决?
编辑:
我不知道YACC版本,但它是Xcode 6.3附带的任何版本.以下是我得到的日志:
CompileC/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/Objects-normal/i386/ViewController.o Parser\Test /ViewController.m正常i386 objective -c com.apple.compilers.llvm.clang.1_0.compiler cd"/ Users/RafaelSoares/Google Drive/Hype/ParserTest-master"export LANG = en_US.US-ASCII export PATH =" /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin :/ sbin"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective -c -arch i386 -fmessage-length = 0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit = 0 -std = gnu99 -Wno-trigraphs -fpascal-strings -O0 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-implicit-atomic-properties -Wno-receiver-is -weak -Wno-arc-repeated-use-of-weak -Wno-missi ng-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wno-empty-body -Wuninitialized -Wno-unknown-pragmas -Wno- shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-shorten-64-to-32 -Wpointer- sign -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wno-undeclared-selector -Wno-deprecated-implementation -DDEBUG = 1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/ iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.3.sdk -fexceptions -fasm-blocks -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -g -Wno-sign-conversion -fobjc-abi-version = 2 -fobjc-legacy- dispatch -mios-simulator-version-min = 8.3 -iquote/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/ Parser\Test-generated-fil es.hmap -I/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/Parser\Test-own-target- headers.hmap -I/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/Parser\Test-all-target- headers.hmap -iquote/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/Parser\Test-project-headers. hmap -I/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Products/Debug-iphonesimulator/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/DerivedSources/i386 -I/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/DerivedSources -F/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Products/Debug-iphonesimulator -include/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/PrecompiledHeaders/Parser\Test-Prefix-gydtbjgblnmtxcahwzhxkvmnznwf/Parser\Test-Prefix.pch -MMD -MT dependencies -MF/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test- ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/Objects-normal/i386/ViewController.d --serialize-diagnostics/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test -ahryrrrgjyqtbhenhxphagqdg ppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/Objects-normal/i386/ViewController.dia -c/Users/RafaelSoares/Google\Drive/Hype/ParserTest-master\/ Parser\Test/ViewController.m -o/Users/RafaelSoares/Library/Developer/Xcode/DerivedData/Parser_Test-ahryrrrgjyqtbhenhxphagqdgppf/Build/Intermediates/Parser\Test.build/Debug-iphonesimulator/Parser\Test.build/Objects-normal/i386 /ViewController.o
在/ Users/RafaelSoares/Google Drive/Hype/ParserTest-master/Parser Test/ViewController.m中包含的文件:5:/ Users/RafaelSoares/Google Drive/Hype/ParserTest-master /parser.ym:14:5:错误:未知类型名称'HYPLangNodeNP'HYPLangNodeNP*nodeNP; ^/Users/RafaelSoares/Google Drive/Hype/ParserTest-master /parser.ym:15:5:错误:未知类型名称'HYPLangNodeVP'HYPLangNodeVP*nodeVP; ^/Users/RafaelSoares/Google Drive/Hype/ParserTest-master /parser.ym:16:5:错误:未知类型名称'HYPLangNode'HYPLangNode*node; ^/Users/RafaelSoares/Google Drive/Hype/ParserTest-master /parser.ym:17:5:错误:未知类型名称'HYPLangSentence'HYPLangSentence*句子; ^/Users/RafaelSoares/Google Drive/Hype/ParserTest-master/Parser Test/ViewController.m:404:34:警告:未使用的变量'child'[-Wunused-variable] NSMutableArray*child = [childsVP [i] getChilds] ; ^ 1警告和4个错误生成.
Bri*_*汤莱恩 15
我已经看了这个并得到了一些答案,但不幸的是,在可用时间内并不是一个完整的工作示例.我对lex&yacc非常熟悉,但之前没有使用过Objective-C.这是我担心的第一次Objective-C练习,而那部分让我失望的是我的弱点.也许您在该领域的更好知识将允许您完成任务.
正如@Ewan Mellor所暗示的那样,问题的第一部分在bison手册*中进行了解释,其中表明yacc为某些语言/编译器生成错误顺序的代码.这对于Objective-C来说是正确的,这是导致您收到的编译错误的原因.具体而言,这意味着%unionyacc 的构造很难与Objective-C对象一起使用(如您所发现的).
有如图所示(在月底)解决这个问题的另一种方式这篇文章.
一个使用YYSTYPE宏来替换yacc使用的类型而不是%union.
我做了以下更改以使用此方法:
在MessageBlocks.h中:
@interface HYPLangNodeNP : NSObject
@end
@interface YYresultType : NSObject
- (float) value;
- (NSString *) identifier;
- (HYPLangNodeNP *)node;
- (void) setvalue: (float)input;
- (void) setidentifier: (NSString *)input;
- (void) setnode: (HYPLangNodeNP *)input;
@end
Run Code Online (Sandbox Code Playgroud)
在MessageBlocks.m中:
@implementation HYPLangNodeNP : NSObject
int dummy;
@end
@implementation YYresultType : NSObject
float value;
NSString *identifier;
HYPLangNodeNP *node;
- (float) value {
return value;
}
- (NSString *) identifier {
return identifier;
}
- (HYPLangNodeNP *) node {
return node;
}
- (void) setvalue: (float)input {
value = input;
}
- (void) setidentifier: (NSString *)input {
identifier = input;
}
- (void) setnode: (HYPLangNodeNP *)input {
node = input;
}
Run Code Online (Sandbox Code Playgroud)
在tokenizer.lm中:
[0-9]+\.[0-9]* { [yylval setvalue: [float atof(yytext)]]; return FLOAT; }
[0-9]+ { [yylval setvalue: [float atof(yytext)]]; return INTEGER; }
[a-zA-Z]+ { [yylval setidentifier : [ [NSString stringWithFormat:@"%s", yytext] retain]; return IDENTIFIER; }
Run Code Online (Sandbox Code Playgroud)
在Parser.ym中:
%{
#import "MessageBlocks.h"
int yylex(void);
void yyerror(char *s);
#define YYSTYPE YYresultType
%}
/*
%union {
float value;
NSString *identifier;
HYPLangNodeNP *node;
}*/
...
and so on.
Run Code Online (Sandbox Code Playgroud)
我仍然得到Objective-C编译错误,所以我没有比你更进一步,但我会继续努力......但可能它对你没用.
本节一直关注的是解释四种Prologue替代方案相对于原始Yacc Prologue的优势.
它解释了yacc代码排序的弱点以及bison如何克服该%code指令.它是yacc而不是内置于Xcode的野牛.可以用系统中的野牛代替yacc来克服这种缺陷.
| 归档时间: |
|
| 查看次数: |
1215 次 |
| 最近记录: |