2015-05-19 14 views
18

Sto cercando di utilizzare YACC con xcode, che è supportato nativamente, e per questo motivo ho trovato l'esempio this che funziona correttamente. La mia idea è di costruire la mia grammatica, quindi ho iniziato a sperimentare con il progetto per vedere se avrebbe supportato ciò di cui avevo bisogno. Come tale, ho creato la seguente interfaccia:"Nome tipo sconosciuto" utilizzando YACC con xcode

.h

#import <Foundation/Foundation.h> 

@interface HYPLangNodeNP : NSObject 

@end 

.m

#import "HYPLangNodeNP.h" 

@implementation HYPLangNodeNP 

@end 

Sì, è solo un'implementazione vuota. Poi ho fatto solo due modifiche alla grammatica:

1) Aggiungere il HYPLangNodeNP importare

%{ 

#import "MessageBlocks.h" 
#import "HYPLangNodeNP.h" 

int yylex(void); 
void yyerror(char *s); 

%} 

2) Aggiungi HYPLangNodeNP al tipo% unione

%union { 
    float  value; 
    NSString *identifier; 
    HYPLangNodeNP *node; 
} 

Il progetto non riesce a compilare con Unknown type name 'HYPLangNodeNP' . Qualcuno sa come risolvere?

Edit:

non so la versione YACC, ma è qualunque navi versione con Xcode 6.3. Quello che segue è il registro ottengo:

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 normal 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-missing-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-implementations -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-files.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-ahryrrrgjyqtbhenhxphagqdgppf/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

In file included from /Users/RafaelSoares/Google Drive/Hype/ParserTest-master /Parser Test/ViewController.m:5: /Users/RafaelSoares/Google Drive/Hype/ParserTest-master /parser.ym:14:5: error: unknown type name 'HYPLangNodeNP' HYPLangNodeNP * nodeNP; ^/Users/RafaelSoares/Google Drive/Hype/ParserTest-master /parser.ym:15:5: error: unknown type name 'HYPLangNodeVP' HYPLangNodeVP * nodeVP; ^/Users/RafaelSoares/Google Drive/Hype/ParserTest-master /parser.ym:16:5: error: unknown type name 'HYPLangNode' HYPLangNode * node; ^/Users/RafaelSoares/Google Drive/Hype/ParserTest-master /parser.ym:17:5: error: unknown type name 'HYPLangSentence' HYPLangSentence * sentence; ^/Users/RafaelSoares/Google Drive/Hype/ParserTest-master /Parser Test/ViewController.m:240:34: warning: unused variable 'child' [-Wunused-variable] NSMutableArray * child = [childsVP[i] getChilds]; ^1 warning and 4 errors generated.

+0

È necessario mostrare l'intera riga di comando e il registro degli errori in modo che possiamo vedere cosa sta succedendo. In Xcode: Comando-8, trova il comando che non sta funzionando, quindi passa il mouse sopra e fai clic sull'icona dell'hamburger per vedere i dettagli completi (lo so, simples, giusto?) –

+0

La mia ipotesi è che "il codice% richiede" aiuterà: http : //www.gnu.org/software/bison/manual/html_node/_0025code-Summary.html#g_t_0025code-Summary "... In altre parole, è il posto migliore per definire i tipi di referenza in% union directives." –

+0

Anche , dovresti dire quale implementazione yacc/bison e versione stai usando. –

risposta

15

Ho guardato questo e hanno alcune risposte, ma purtroppo, non un esempio di lavoro completo nel tempo a disposizione. Conosco molto bene lex & ma non ho mai lavorato con Objective-C. Questo è stato il mio primo esercizio Objective-C, ho paura, ed è stata la mia debolezza in quella parte che mi ha deluso. Forse la tua migliore conoscenza in quell'area ti consentirà di completare il compito.

La prima parte del problema, come suggerito da @Ewan Mellor, è spiegata nel manuale bisonte * dove indica che yacc genera codice nell'ordine errato per alcune lingue/compilatori. Questo è vero per Objective-C, che è ciò che causa l'errore di compilazione che si sta ricevendo. Ciò significa, in particolare, che il costrutto di yacc %union è difficile da utilizzare in combinazione con oggetti Objective-C (come hai scoperto).

C'è un altro modo di risolvere questo problema come mostrato (alla fine di) this article.

Si utilizza la macro YYSTYPE per sostituire il tipo utilizzato da yacc anziché %union.

Ho fatto le seguenti modifiche di utilizzare questo metodo:

In 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 

In 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; 
} 

In 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; } 

In Parse r.YM:

%{ 

#import "MessageBlocks.h" 

int yylex(void); 
void yyerror(char *s); 
#define YYSTYPE YYresultType 
%} 

/* 
%union { 
    float  value; 
    NSString *identifier; 
    HYPLangNodeNP *node; 
}*/ 

... 

and so on. 

sto ancora ricevendo errori di compilazione Objective-C, quindi io non sono più avanti di quello che erano, ma io continuerò a lavorare su di esso ... ma probabilmente non sarà utile a te.


* Vedi ultimo paragrafo del this section:

This section has been concerned with explaining the advantages of the four Prologue alternatives over the original Yacc Prologue.

Essa spiega la debolezza del codice yacc ordinazione e come bisonti supera che con la direttiva %code. È yacc e non bison che è incorporato in Xcode. Sarebbe possibile sostituire yacc con bisonti sul sistema per superare questa carenza.

Problemi correlati