home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lr.zip / LR_GUIDE.INF (.txt) < prev    next >
OS/2 Help File  |  1993-05-15  |  131KB  |  5,701 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. QuickStart ΓòÉΓòÉΓòÉ
  3.  
  4. Example of how to compile and use a grammar. 
  5.  
  6.  1. Open an OS2 window and create a directory on your hard drive, preferably 
  7.     C:\LR.  Make this the current directory. 
  8.  
  9.  2. Copy the contents of the installation diskette into the current directory. 
  10.  
  11.         COPY A:*
  12.  
  13.     assuming A: is the drive you are installing from. 
  14.  
  15.  3. From the command line, enter: 
  16.  
  17.         LRP LR_SQL.GR LR_SQL.SQL
  18.  
  19.     This will compile the SQL grammar in LR_SQL.GR, and parse the SQL 
  20.     statements in LR_SQL.SQL.  The SQL grammar compilation takes 23 seconds on 
  21.     a 486dx50 with 20M.  Subsequently you may enter: 
  22.  
  23.         LRP LR_SQL.LRS LR_SQL.SQL
  24.  
  25.     to reuse the compiled grammar in the .LRS file. 
  26.  
  27.  4. Enter: 
  28.  
  29.         EPM LR_SQL.PRS
  30.  
  31.     to view the parse tree produced by LR.  You may have to scroll down to see 
  32.     it. 
  33.  
  34.  5. To create your own grammar, copy LR_SQL.GR to another .GR file and edit the 
  35.     grammar rules.  Optionally, place sample source statements into another 
  36.     file. Rerun LRP, whose syntax is: 
  37.  
  38.         LRP <grammar.gr | grammar.lrs> [text]
  39.  
  40.     a. Grammar file to be compiled (.GR) or compiled grammar (.LRS) 
  41.  
  42.     b. Optional text file containing source statements to be parsed. 
  43.  
  44.  6. Program LR_SQL.C (and its make file LR_SQL.MAK), show you how to request LR 
  45.     processing from a program by: 
  46.  
  47.     a. Including the generated .STR and .CC files generated from your grammar 
  48.  
  49.     b. Specifying semantic routines for each nonterminal you wish to process 
  50.  
  51.     c. Filling out  structure LRX_REQ  to request a parse. 
  52.  
  53.     d. Invoking procedure lrx_req  to perform a parse. 
  54.  
  55.  7. If you have wasted hours being frustrated by LEX and YACC, relax! You know 
  56.     more than enough to use LR.  Just remember, there is: 
  57.  
  58.     a. No lexical phase, as lexical analysis is handled by string non terminals 
  59.        in the grammar, which concatenate their terminals to form lexical 
  60.        tokens. 
  61.  
  62.     b. No semantic actions to be imbedded into the grammar 
  63.  
  64.     c. No generated C code to compile and link 
  65.  
  66.     d. No time wasted, - our largest grammar - SQL - compiles in 23 seconds! 
  67.  
  68.  8. Select this line to get addressability to the most useful chapters in this 
  69.     guide. 
  70.  
  71.  9. Thank you for taking the time to examine LR.  Non stop support, 
  72.     maintenance, enhancements, and further development is all provided free via 
  73.     your Transcendental Automation Support Representative: Phil Brenan, at 
  74.     Compuserve 71022,3620. 
  75.  
  76. 10. Get free hardware everytime you sell a copy of LR!  E-mail your techical 
  77.     support representative for details. 
  78.  
  79.  
  80. ΓòÉΓòÉΓòÉ 2. Introduction. ΓòÉΓòÉΓòÉ
  81.  
  82. This guide discusses the production of an LR parser for a given language from 
  83. the context free grammar representing the language.  A solution to the 
  84. difficult problem of designing a parser regardless of the source language or 
  85. target machine is presented.  To make the guide self-contained a few basic 
  86. concepts are introduced, as well as the terminology of parser design.  All 
  87. necessary language facilities, data structures, macros, procedures and 
  88. technical details required to parse your own language are presented in this 
  89. guide. 
  90.  
  91.  
  92. ΓòÉΓòÉΓòÉ 2.1. LR by Transcendental Automation ΓòÉΓòÉΓòÉ
  93.  
  94. LR may be used to build complete front-ends for programming language 
  95. compilation systems, partial front ends for recognizing key elements within a 
  96. language (for example:  host variables within a SQL SELECT statement), as well 
  97. as text processors of many sorts from simple text editors to sophisticated 
  98. pattern recognition programs. 
  99.  
  100. Designing a language to deliver the functionality of your product is well worth 
  101. the effort, as it gives your users a simple, flexible means to combine the 
  102. features of your products in an exponential number of ways. 
  103.  
  104.  
  105. ΓòÉΓòÉΓòÉ 2.2. LR(k) parser choice rational ΓòÉΓòÉΓòÉ
  106.  
  107. Their are a variety of technical reasons to use LR parsing: 
  108.  
  109. o LR-parsers can be constructed for a wide range of languages whose syntactic 
  110.   structure can be defined by a context-free grammar; 
  111.  
  112. o  The LR parsing method is more general than any of the other common 
  113.   shift-reduce techniques, yet it can be implemented with the acceptable degree 
  114.   of efficiency; 
  115.  
  116. o LR-parsers can detect syntactic errors as soon as it is possible to do so on 
  117.   a left-to-right scan of the input. 
  118.  
  119.  
  120. ΓòÉΓòÉΓòÉ 2.3. Brief overview of LR usage ΓòÉΓòÉΓòÉ
  121.  
  122. Usage of LR assumes following steps: 
  123.  
  124.  1. Source language grammar specification. 
  125.  
  126.  2. LR-parsing automaton construction. 
  127.  
  128.  3. Source text parsing with parse-tree construction. 
  129.  
  130.  4. Syntax-directed semantic processing of parse tree. 
  131.  
  132.  5. Error message interpretation as necesssary 
  133.  
  134.  
  135. ΓòÉΓòÉΓòÉ 2.4. LR-parser host language ΓòÉΓòÉΓòÉ
  136.  
  137. The host language for LR is at present C. The LR library, data structures, 
  138. macros and procedures needed for the use of LR are all in C, so you will need 
  139. to be familiar with the C language. 
  140.  
  141.  
  142. ΓòÉΓòÉΓòÉ 2.5. LR - (LEX+YACC) technologies comparison ΓòÉΓòÉΓòÉ
  143.  
  144. A brief comparison with the infamous LEX/YACC duo may serve to high light some 
  145. of the reasons for choosing to use LR instead, while providing an overview of 
  146. the key features of LR: 
  147.  
  148. One phase           LR does not have separate lexical and syntactic phases.  It 
  149.                     is well known that context free grammars (YACC) can 
  150.                     represent regular expressions (LEX), so why have two 
  151.                     separate phases?  Having only one representation to 
  152.                     maintain means less debugging of the resulting grammar. 
  153.  
  154. LR(k) versus LALR(1) An LR(k) grammar is more powerful than an LALR(1) and 
  155.                     permits the poarsing of a wider class of languages. 
  156.  
  157. No imbeds           LR does not imbed semantic actions.  This has multiple 
  158.                     benefits. It means that one grammar can drive several sets 
  159.                     of semantic actions, eliminating the need to maintain 
  160.                     multiple versions of the same grammar which are identical 
  161.                     except for their semantic actions. 
  162.  
  163. No C Code           LR does not produce C code.  This means that you can 
  164.                     construct grammars dynamically if you wish and compile them 
  165.                     as necessary.  The actual output of LR is a relocatable set 
  166.                     of tables which describe the actions of the parser. 
  167.  
  168. Parse tree          LR produces an in-memory parse tree.  LR comes complete 
  169.                     with procedures for navigating the parse tree.  One 
  170.                     immediate benefit, the parse tree can be printed, to show 
  171.                     you the syntactic structure of your input language 
  172.                     statements. 
  173.  
  174. Analysis            LR provides a detailed error analysis of a failing parse, 
  175.                     which can be decoded by a user supplied routine, or printed 
  176.                     via the standard error processing procedure. 
  177.  
  178.  
  179. ΓòÉΓòÉΓòÉ 3. Parsing brief overview ΓòÉΓòÉΓòÉ
  180.  
  181. This chapter introduces many of the basic concepts of LR parsing. 
  182.  
  183. In order for LR to parse a language, it must be described by a context-free 
  184. grammar.  This means that you specify one or more syntactic aggregations  and 
  185. give rules for constructing them from their parts.  For example, in the C 
  186. language, one kind of aggregation is called an expression.  One rule for making 
  187. an expression might be, An expression can be made of a minus sign and another 
  188. expression.  Another would be, An expression can be an integer.  As you can 
  189. see, rules are often recursive, but there must be at least one rule which leads 
  190. out of the recursion. 
  191.  
  192. The most common formal system for presenting such rules is Backus-Naur Form or 
  193. BNF. Any grammar expressed in BNF is a context-free grammar.  The input to LR 
  194. is essentially machine-readable BNF. 
  195.  
  196. Not all context-free languages can be handled by LR, only those that are LR(k). 
  197. In brief, this means that it must be possibly to tell how to parse any portion 
  198. of an input string with just a k character of look-ahead. See  Reduce/Reduce 
  199. Conflicts, for more information on this. 
  200.  
  201. In the formal grammatical rules for a language, each kind of syntactic unit or 
  202. aggregation is named by a symbol.  Those which are built by aggregating smaller 
  203. constructs according to grammatical rules are called nonterminal symbols; those 
  204. which cannot be subdivided are called terminal symbols.  We call a piece of 
  205. input corresponding to a single terminal symbol a token, and a piece 
  206. corresponding to a single nonterminal symbol an aggregation. 
  207.  
  208. We can use the C language as an example of what symbols, terminal and 
  209. nonterminal, mean. 
  210.  
  211. The terminal symbols of a grammar for C include the various keywords: if, 
  212. return, const, static, int, char and literals: asterisk, semicolon, open-paren, 
  213. close-paren, open-brace, close-brace and many more. 
  214.  
  215. Here is a simple C function subdivided into tokens: 
  216.  
  217. int                 // keyword int
  218. square (x)          // identifier, open-paren
  219.                     // identifier, close-paren
  220.      int x;         // keyword int, identifier, semicolon
  221.    {                // open-brace
  222.       return x * x; // keyword return, identifier
  223.                     // asterisk, identifier, semicolon
  224.     }               // close-brace
  225.  
  226. The syntactic aggregations of C include the identifier, the expression, the 
  227. statement, the declaration, and the function definition. These are represented 
  228. in the grammar of C by nonterminal symbols expression, statement, declaration 
  229. and function definition.  The full grammar uses dozens of additional language 
  230. constructs, each with its own nonterminal symbol, in order to express the 
  231. meanings of these four.  The example above is a function definition; it 
  232. contains one declaration, and one statement.  In the statement, each x is an 
  233. expression and so is x * x. 
  234.  
  235. Each nonterminal symbol must have grammatical rules showing how it is made out 
  236. of simpler constructs.  For example, one kind of C statement is the return 
  237. statement; this would be described with a grammar rule which reads informally 
  238. as follows: 
  239. A statement can be made of a return keyword, an expression and a semicolon. 
  240.  
  241. There would be many other rules for statement, one for each kind of statement 
  242. in C. 
  243.  
  244. One nonterminal symbol must be distinguished as the special one which defines a 
  245. complete utterance in the language.  It is called the start symbol. In a 
  246. compiler, this means a complete input program.  In the C language, the 
  247. nonterminal symbol sequence of definitions and declarations plays this role. 
  248.  
  249. For example, 1 + 2 is a valid C expression---a valid part of a C program---but 
  250. it is not valid as an entire C program.  In the context-free grammar of C, this 
  251. follows from the fact that expression is not the start symbol. 
  252.  
  253. The LR parser reads a sequence of tokens as its input, and groups the tokens 
  254. using the grammar rules.  If the input is valid, the end result is that the 
  255. entire token sequence reduces to a single aggregation whose symbol is the 
  256. grammar's start symbol.  If we use a grammar for C, the entire input must be a 
  257. sequence of definitions and declarations.  If not, the parser reports a syntax 
  258. error. 
  259.  
  260. A formal grammar is a mathematical construct.  To define the language for LR, 
  261. you must write a file expressing the grammar in LR syntax: a LR grammar file . 
  262.  
  263. A nonterminal symbol in the formal grammar is represented in LR input as an 
  264. identifier, like an identifier in C. 
  265.  
  266. A terminal symbol is represented as a character literal, just like a C 
  267. character constant. 
  268.  
  269. The grammar rules also have an expression in LR syntax.  For example, here is 
  270. the LR rule for a C return  statement.  The semicolon in quotes is a terminal, 
  271. representing part of the C syntax for the statement. 
  272.  
  273.         stmt      (return expr semicolon)
  274.         return    ('return')
  275.         semicolon (';')
  276.  A formal grammar selects tokens only by their classifications: for example, if 
  277. a rule mentions the nonterminal symbol integer constant, it means that any 
  278. integer constant is grammatically valid in that position.  The precise value of 
  279. the constant is irrelevant to how to parse the input: if x+4 is grammatical 
  280. then x+1 or x+3989 is equally correct. 
  281.  
  282. The precise value is very important for what the input means once it is parsed. 
  283. Therefore, each token in a LR grammar has a semantic value. 
  284.  
  285. The semantic value has all the rest of the information about the meaning of the 
  286. token, such as the value of an integer. 
  287. (A token such as ','  which is just punctuation doesn't need to have any 
  288. semantic value.) 
  289.  
  290. When the parser accepts the token, it keeps track of the token's semantic 
  291. value. 
  292.  
  293. Each aggregation can also have a semantic value as well as its nonterminal 
  294. symbol.  For example, in a compiler for a programming language, an expression 
  295. typically has a semantic value that is a tree structure describing the meaning 
  296. of the expression. 
  297.  
  298. In order to be useful, a program must do more than parse input: it must also 
  299. produce some output based on the input.  In an LR grammar, a grammar rule can 
  300. have an action  made up of a C procedure. 
  301.  
  302. Most of the time, the purpose of an action is to compute the semantic value of 
  303. the whole construct from the semantic values of its parts.  For example, 
  304. suppose we have a rule which says an expression can be the sum of two 
  305. expressions.  When the parser recognizes such a sum, each of the subexpressions 
  306. has a semantic value which describes how it was built up. The action for this 
  307. rule should create a similar sort of value for the newly recognized larger 
  308. expression. 
  309.  
  310. For example, here is a rule that says an expression can be the sum of two 
  311. subexpressions: 
  312.  
  313.         expr  (expr plus expr1)
  314.         expr1 (expr)
  315.         plus  ('+')
  316.  
  317. The action says how to produce the semantic value of the sum expression from 
  318. the values of the two subexpressions. 
  319.  
  320. When you run LR, you give it an LR grammar file as input.  The output is a 
  321. parsing table that enables you to parse the language described by the grammar. 
  322.  
  323. This parsing table with the LR utility is called a LR parser that becomes part 
  324. of your program. 
  325.  
  326. The job of the LR parser is to group tokens into aggregations according to the 
  327. grammar rules---for example, to build identifiers and operators into 
  328. expressions.  As it does this, it creates a persistent parse tree which shows 
  329. the grammar rules which have been applied.  Subsequently, this parse tree may 
  330. be traversed to drive semantic processing. 
  331.  
  332. The LR parser work as follows: 
  333.  
  334. As LR parser reads tokens, it pushes them onto a stack. The stack is called the 
  335. parser stack.  Pushing a token is traditionally called shifting. 
  336.  
  337. The stack does not always have an element for each token read. When the last 
  338. tokens and aggregations shifted match the components of a grammar rule, they 
  339. can be combined according to that rule.  This is called reduction.  Those 
  340. tokens and aggregations are replaced on the stack by a single aggregation whose 
  341. symbol is the result (left hand side) of that rule. The nonterminals on the 
  342. right hand-side are suspended from the nonterminal on the left hand side to 
  343. create a node in the persistant parse tree. 
  344.  
  345. The parser tries, by shifts and reductions, to reduce the entire input down to 
  346. a single aggregation whose symbol is the grammar's start-symbol 
  347.  
  348. This kind of parser is known in the literature as a bottom-up parser. 
  349.  
  350.  
  351. ΓòÉΓòÉΓòÉ 3.1. Context-free grammars ΓòÉΓòÉΓòÉ
  352.  
  353.  A widely used technique to specify the syntactic structure of a language is a 
  354. context free grammar.  A grammar gives a precise, yet easy to understand, 
  355. syntactic specification for the text of a statement in the language.  An 
  356. efficient parser can be constructed automatically from a properly designed 
  357. grammar.  A grammar imparts a structure to the text that is useful for deciding 
  358. the appropriate semantic processing and for the detection of errors. 
  359.  
  360. LR supplies a special notation for defining context free grammars, it is called 
  361. "Grammar Definition Language" or GDL. (GDL). 
  362.  
  363. Context free grammars consist of one or more productions. 
  364.  
  365. The productions describe how a syntactically correct statement in the language 
  366. specified by the grammar, may be produced from the START symbol of the grammar. 
  367.  
  368. Each productions has  a left hand side (LHS) and a right hand side (RHS). 
  369.  
  370. The left hand side of a production is a single nonterminal. 
  371.  
  372. The right hand side of a production is either one or more nonterminals, or one 
  373. or more terminals. 
  374.  
  375. It is customary to separate the LHS from the RHS side of a production by the 
  376. use of some arbitrary symbol like ->, although this is only to aid readability. 
  377. In GDL, the RHS is parenthesesed and placed after the LHS. 
  378.  
  379.  
  380. ΓòÉΓòÉΓòÉ 3.1.1. Productions ΓòÉΓòÉΓòÉ
  381.  
  382. The productions describe how a syntactically correct statement in the language 
  383. specified by the grammar, may be produced from the START symbol of the grammar. 
  384.  
  385. Each productions have  a left hand side (LHS) and a right hand side (RHS). 
  386.  
  387. The left hand side of a production is a single nonterminal. 
  388.  
  389. The right hand side of a production is either one or more nonterminals, or one 
  390. or more terminals. 
  391.  
  392. It is customary to separate the LHS from the RHS side of a production by the 
  393. use of some arbitrary symbol like ->, although this is only to aid readability. 
  394. In GDL, the RHS is parenthesesed and placed after the LHS. 
  395.  
  396.  
  397. ΓòÉΓòÉΓòÉ 3.1.2. Right hand side of a production (RHS) ΓòÉΓòÉΓòÉ
  398.  
  399. The right hand side of a production is either one or more nonterminals, or one 
  400. or more terminals. 
  401.  
  402. (It is possible to formulate context free grammars with RHS's consisting of a 
  403. mixture of nonterminals and terminals, however, there is no loss in generality 
  404. in making this slight restriction, and it does make processing the resulting 
  405. parse tree simpler.) 
  406.  
  407.  
  408. ΓòÉΓòÉΓòÉ 3.1.3. The left hand side of a production (LHS) ΓòÉΓòÉΓòÉ
  409.  
  410. The left hand side of a production is a single nonterminal. 
  411.  
  412. The same nonterminal may occur as the LHS of several production. 
  413.  
  414.  
  415. ΓòÉΓòÉΓòÉ 3.1.4. Terminals ΓòÉΓòÉΓòÉ
  416.  
  417. Terminals are character constants describing the characters that may appear in 
  418. a given context.  In GDL, terminals are always designated by quoted strings. 
  419.  
  420.  
  421. ΓòÉΓòÉΓòÉ 3.1.5. Nonterminals ΓòÉΓòÉΓòÉ
  422.  
  423. Nonterminal describe the class of constituents of the language. A nonterminal 
  424. is described in terms of other nonterminals and terminals. Such a description 
  425. of a nonterminal is called a production. In GDL, nonterminals are designated by 
  426. any sequence of symbols which does not contain quotes, blanks, or parenthesis. 
  427.  
  428. In GDL, a given nonterminal may appear at most once in the RHS of a single 
  429. production. This is not a severe restriction, as you can use other productions 
  430. to generate several names for the same underlying nonterminal.  This 
  431. restriction serves to simplify the processing of the parse trees constructed by 
  432. the parser. 
  433.  
  434. One nonterminal is designated the start nonterminal. In GDL,this is the first 
  435. nonterminal encountered in the rules section. 
  436.  
  437.  
  438. ΓòÉΓòÉΓòÉ 3.1.6. Start nonterminal ΓòÉΓòÉΓòÉ
  439.  
  440. One nonterminal is selected as the start symbol, and it denotes the language of 
  441. your interest. In GDL, this is the first nonterminal encountered in the rules 
  442. section. 
  443.  
  444.  
  445. ΓòÉΓòÉΓòÉ 3.2. LR(k) parsing and parse trees ΓòÉΓòÉΓòÉ
  446.  
  447. The job of the LR parser is to group tokens into aggregations according to the 
  448. grammar rules---for example, to build identifiers and operators into 
  449. expressions.  As it does this, it builds a persistant parse tree which may then 
  450. be traversed to drive semantic processing. 
  451.  
  452. The LR parser work as follows: 
  453.  
  454. As LR parser reads tokens, it pushes them onto a stack. Pushing a token is 
  455. traditionally called shifting. 
  456.  
  457. But the stack does not always have an element for each token read.  When the 
  458. last tokens and aggregations shifted match the components of a grammar rule, 
  459. they can be combined according to that rule.  This is called reduction.  Those 
  460. tokens and aggregations are replaced on the stack by a single aggregation whose 
  461. symbol is the result (left hand side) of that rule. The nonterminals on the 
  462. right hand-side are suspended from the nonterminal on the left hand side to 
  463. create a node in the persistant parse tree. 
  464.  
  465. The parser tries, by shifts and reductions, to reduce the entire input down to 
  466. a single aggregation whose symbol is the grammar's start-symbol 
  467.  
  468. On a logical level the output of the parsing of a source text is some 
  469. representation of a parse tree, that making explicit the hierarchical syntactic 
  470. structure of the source text that is implied by the grammar. 
  471.  
  472. Each interior node of the parse tree corresponds to some nonterminal A and the 
  473. children of the node correspond, from left to right, to the symbols in the 
  474. right side of the production by which this A was replaced in the derivation. 
  475. For example, if  A(X Y Z)  is a production used at some step of a derivation, 
  476. then the parse tree for that derivation will have the subtree: 
  477.  
  478.                        A
  479.                        Γöé
  480.                 ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  481.                 Γöé      Γöé      Γöé
  482.                 X      Y      Z
  483.  
  484. A(X Y Z) parse tree graphical  representation.
  485.  
  486. Sometimes another equivalent graphical representation for parse tree will be 
  487. used: 
  488.  
  489.                        A
  490.                        Γöé
  491.                        Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ X
  492.                        Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ Y
  493.                        ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ Z
  494.  
  495.  
  496.  
  497. Another parse tree graphical representation. 
  498.  
  499.  
  500. ΓòÉΓòÉΓòÉ 3.3. Grammar conflicts ΓòÉΓòÉΓòÉ
  501.  
  502. A grammars that has certain ambiguities are not allowed in LR. Such ambiguities 
  503. are known as  reduce/reduce conflicts. 
  504.  
  505. A  reduce/reduce conflict  occurs if there are two or more rules that apply to 
  506. the same sequence of input.  This usually indicates a serious error in the 
  507. grammar. 
  508.  
  509. A situation, where either a shift or a reduction would be valid, is called a 
  510. shift/reduce conflict. LR is designed to resolve these conflicts by choosing to 
  511. shift, unless otherwise directed by SECONDARY declarations. 
  512.  
  513.  
  514. ΓòÉΓòÉΓòÉ 3.3.1. Shift/Reduce conflicts ΓòÉΓòÉΓòÉ
  515.  
  516. The LR parser does not always reduce immediately as soon as the last n tokens 
  517. and aggregatings match a rule. This is because such a simple strategy is 
  518. inadequate to handle most languages.  Instead, when a reduction is possible, 
  519. the parser sometimes looks ahead at the next token in order to decide what to 
  520. do. 
  521.  
  522. When a token is read, it is not immediately shifted; first it becomes the 
  523. look-ahead token, which is not on the stack.  Now the parser can perform one or 
  524. more reductions of tokens and aggregatings on the stack, while the look-ahead 
  525. token remains off to the side.  When no more reductions should take place, the 
  526. look-ahead token is shifted onto the stack.  This does not mean that all 
  527. possible reductions have been done; depending on the token type of the 
  528. look-ahead token, some rules may choose to delay their application. 
  529.  
  530. Here is a simple case where look-ahead is needed.  These rules define 
  531. expressions which contain binary addition operators and postfix unary factorial 
  532. operators !, and allow parentheses for aggregating. 
  533.  
  534. LR (
  535.         NAME('shf1')
  536.         TITLE('Shift/Reduce 1')
  537.         Struct
  538.         Print
  539.         Rules
  540.           (
  541.             expr  (term plus expr)
  542.                   ( term )
  543.             term  (op expr cl)
  544.                   ( term fct )
  545.                   (  NUMBER  )
  546.             plus ('+')
  547.             op   ('(')
  548.             cl   (')')
  549.             fct  ('!')
  550.             NUMBER ('123456789'(choice))
  551.            )
  552.      )
  553.  Suppose that the tokens 1 + 2 have been read and shifted; what should be done? 
  554. If the following token is ) , then the first three tokens must be reduced to 
  555. form an expr .  This is the only valid course, because shifting the ) would 
  556. produce a sequence of symbols term ')', and no rule allows this.  If the 
  557. following token is ! , then it must be shifted immediately so that 2 ! can be 
  558. reduced to make a term .  If instead the parser were to reduce before shifting, 
  559. 1 + 2 would become an expr. It would then be impossible to shift the ! because 
  560. doing so would produce on the stack the sequence of symbols expr'!'. No rule 
  561. allows that sequence. 
  562.  
  563. For this grammar LR parser, if input text is 1+2! ,produce the following tree: 
  564.  
  565. expr
  566. Γö£ΓöÇterm
  567. Γöé ΓööΓöÇNUMBERΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ1
  568. Γö£ΓöÇplusΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ+
  569. ΓööΓöÇexpr
  570.   ΓööΓöÇterm
  571.     Γö£ΓöÇterm
  572.     Γöé ΓööΓöÇNUMBERΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ2
  573.     ΓööΓöÇfctΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ!
  574.  
  575. Suppose we are parsing a language which has if-then and if-then-else 
  576. statements, with a of rules like this: 
  577.  
  578. LR
  579.   (
  580.      NAME(IF_STMT)
  581.      TITLE('If-statement')
  582.      RULES
  583.        (
  584.           if_stmt0    ( if_stmt1 )
  585.           if_stmt0    ( if_stmt2 )
  586.  
  587.           if_stmt1    (_IF expr _THEN stmt )
  588.           if_stmt2    (_IF expr _THEN stmt _ELSE stmt1 )
  589.  
  590.           stmt        ( stmt1 )
  591.           stmt1       ( operator )
  592.                       ( if_stmt0   )
  593.  
  594.           operator    ('operator'(MIXED))
  595.  
  596.           _IF         ( 'if' )
  597.           _THEN       ( 'then' )
  598.           _ELSE       ( 'else' )
  599.           expr        (term plus expr)
  600.                       ( term )
  601.           term        (op expr cl)
  602.                       ( term fct )
  603.                       (  NUMBER  )
  604.           plus       ('+')
  605.           op         ('(')
  606.           cl         (')')
  607.           fct        ('!')
  608.           NUMBER     ('123456789'(choice))
  609.         )
  610.         string ( _IF _THEN _ELSE )
  611.         mixed  ( _IF _THEN _ELSE )
  612.    )
  613.  
  614. (Here we assume that _IF , _THEN  and _ELSE  are terminal symbols for specific 
  615. keyword tokens.) 
  616.  
  617. When the _ELSE token is read and becomes the look-ahead token, the contents of 
  618. the stack (assuming the input is valid) are just right for reduction by the 
  619. first rule.  But it is also legitimate to shift the _ELSE, because that would 
  620. lead to eventual reduction by the second rule. 
  621.  
  622. This situation, where either a shift or a reduction would be valid, is called a 
  623. shift/reduce conflict.  LR is designed to resolve these conflicts by choosing 
  624. to shift, unless otherwise directed by SECONDARY declarations. 
  625.  
  626. Since the parser prefers to shift the _ELSE , the result is to attach the 
  627. else-clause to the innermost if-statement. 
  628.  
  629. For input text: 
  630.  
  631. if 1
  632. then
  633.    if 2
  634.    then operator
  635.    else operator
  636.  
  637. LR parser produce the following tree: 
  638.  
  639. if_stmt0
  640. ΓööΓöÇif_stmt1
  641.   Γö£ΓöÇ_IFΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇif
  642.   Γö£ΓöÇexpr
  643.   Γöé ΓööΓöÇterm
  644.   Γöé   ΓööΓöÇNUMBERΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ1
  645.   Γö£ΓöÇ_THENΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇthen
  646.   ΓööΓöÇstmt
  647.     ΓööΓöÇstmt1
  648.       ΓööΓöÇif_stmt0
  649.         ΓööΓöÇif_stmt2
  650.           Γö£ΓöÇ_IFΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇif
  651.           Γö£ΓöÇexpr
  652.           Γöé ΓööΓöÇterm
  653.           Γöé   ΓööΓöÇNUMBERΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ2
  654.           Γö£ΓöÇ_THENΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇthen
  655.           Γö£ΓöÇstmt
  656.           Γöé ΓööΓöÇstmt1
  657.           Γöé   ΓööΓöÇoperatorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇoperator
  658.           Γö£ΓöÇ_ELSEΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇelse
  659.           ΓööΓöÇstmt1
  660.             ΓööΓöÇoperatorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇoperator
  661.  But if the parser chose to reduce when possible rather than shift, the result 
  662. would be to attach the else-clause to the outermost if-statement: 
  663.  
  664. if_stmt0
  665. ΓööΓöÇif_stmt2
  666.   Γö£ΓöÇ_IFΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇif
  667.   Γö£ΓöÇexpr
  668.   Γöé ΓööΓöÇterm
  669.   Γöé   ΓööΓöÇNUMBERΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ1
  670.   Γö£ΓöÇ_THENΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇthen
  671.   Γö£ΓöÇstmt
  672.   Γöé ΓööΓöÇstmt1
  673.   Γöé   ΓööΓöÇif_stmt0
  674.   Γöé     ΓööΓöÇif_stmt1
  675.   Γöé       Γö£ΓöÇ_IFΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇif
  676.   Γöé       Γö£ΓöÇexpr
  677.   Γöé       Γöé ΓööΓöÇterm
  678.   Γöé       Γöé   ΓööΓöÇNUMBERΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ2
  679.   Γöé       Γö£ΓöÇ_THENΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇthen
  680.   Γöé       ΓööΓöÇstmt
  681.   Γöé         ΓööΓöÇstmt1
  682.   Γöé           ΓööΓöÇoperatorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇoperator
  683.   Γö£ΓöÇ_ELSEΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇelse
  684.   ΓööΓöÇstmt1
  685.     ΓööΓöÇoperatorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇoperator
  686.  
  687. The conflict exists because the grammar as written is ambiguous: either parsing 
  688. of the simple nested if-statement is legitimate.  The established convention is 
  689. that these ambiguities are resolved by attaching the else-clause to the 
  690. innermost if-statement; this is what LR accomplishes by choosing to shift 
  691. rather than reduce.  (It would ideally be cleaner to write an unambiguous 
  692. grammar, but that is very hard to do in this case.) 
  693.  
  694. Another situation where shift/reduce conflicts appear is in arithmetic 
  695. expressions.  Here shifting is not always the preferred resolution. 
  696.  
  697. Consider the following ambiguous grammar fragment (ambiguous because the input 
  698. 1+2*3 can be parsed in different ways): 
  699.  
  700.  LR
  701.   (
  702.      NAME(A_EXPR1)
  703.      TITLE('Arithmetic expressions 1.')
  704.      RULES
  705.      (
  706.           expr       ( add_expr  )
  707.                      ( mult_expr )
  708.                      ( number )
  709.  
  710.           add_expr   ( expr add_oprt  expr1 )
  711.  
  712.           mult_expr  ( expr mult_oprt expr1 )
  713.  
  714.           expr1      ( expr )
  715.  
  716.           add_oprt       ('+-' (choice))
  717.           mult_oprt      ('*/' (choice))
  718.  
  719.           number     ('123456789'(choice))
  720.      )
  721.    )
  722.  
  723. Suppose the parser has seen the tokens 1+2 should it reduce them via the rule 
  724. for the addition operator?  It depends on the next token.  Of course, if the 
  725. next token is ), we must reduce; shifting is invalid because no single rule can 
  726. reduce the token sequence *2 or anything starting with that.  But if the next 
  727. token is * or \ , we have a choice: either shifting or reduction would allow 
  728. the parse to complete, but with different results: 
  729.  
  730. Firth way of parsing 1+2*3 for the grammar A_EXPR1: 
  731.  
  732.  
  733. expr
  734. ΓööΓöÇadd_expr
  735.   Γö£ΓöÇexpr
  736.   Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ1
  737.   Γö£ΓöÇadd_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ+
  738.   ΓööΓöÇexpr1
  739.     ΓööΓöÇexpr
  740.       ΓööΓöÇmult_expr
  741.         Γö£ΓöÇexpr
  742.         Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ2
  743.         Γö£ΓöÇmult_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ*
  744.         ΓööΓöÇexpr1
  745.           ΓööΓöÇexpr
  746.             ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ3
  747.  
  748. Second way of parsing 1+2*3 for the grammar A_EXPR1: 
  749.  
  750.  
  751. expr
  752. ΓööΓöÇmult_expr
  753.   Γö£ΓöÇexpr
  754.   Γöé Γö£ΓöÇadd_expr
  755.   Γöé Γö£ΓöÇexpr
  756.   Γöé Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ1
  757.   Γöé Γö£ΓöÇadd_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ+
  758.   Γöé ΓööΓöÇexpr1
  759.   Γöé   ΓööΓöÇexpr
  760.   Γöé     ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ2
  761.   Γö£ΓöÇmult_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ*
  762.   ΓööΓöÇexpr1
  763.     ΓööΓöÇexpr
  764.       ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ3
  765.  
  766. LR parsing algorithm built for input text 1+2*3+4*5 the following parse tree: 
  767.  
  768.  
  769. expr
  770. ΓööΓöÇadd_expr
  771.   Γö£ΓöÇexpr
  772.   Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ1
  773.   Γö£ΓöÇadd_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ+
  774.   ΓööΓöÇexpr1
  775.     ΓööΓöÇexpr
  776.       ΓööΓöÇmult_expr
  777.         Γö£ΓöÇexpr
  778.         Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ2
  779.         Γö£ΓöÇmult_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ*
  780.         ΓööΓöÇexpr1
  781.           ΓööΓöÇexpr
  782.             ΓööΓöÇadd_expr
  783.               Γö£ΓöÇexpr
  784.               Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ3
  785.               Γö£ΓöÇadd_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ+
  786.               ΓööΓöÇexpr1
  787.                 ΓööΓöÇexpr
  788.                   ΓööΓöÇmult_expr
  789.                     Γö£ΓöÇexpr
  790.                     Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ4
  791.                     Γö£ΓöÇmult_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ*
  792.                     ΓööΓöÇexpr1
  793.                       ΓööΓöÇexpr
  794.                         ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ5
  795.  
  796. Clearly, then, the choice of shift or reduce should depend on the relative 
  797. precedence of the operators. 
  798.  
  799. To resolve the operator precedence problem the grammar must be rewrite as 
  800. follows: 
  801.  
  802. LR
  803.   (
  804.      NAME(A_EXP2)
  805.      TITLE('Arithmetic expressions 2.')
  806.      RULES
  807.      (
  808.           expr       ( add_expr  )
  809.                      ( mult_expr )
  810.  
  811.           add_expr   ( mult_expr add_oprt  mult_expr1 )
  812.                      ( add_expr  add_oprt  mult_expr   )
  813.  
  814.           mult_expr  ( mult_expr mult_oprt mult_expr1 )
  815.                      ( number )
  816.  
  817.           mult_expr1 ( mult_expr )
  818.  
  819.           add_oprt       ('+-' (choice))
  820.           mult_oprt      ('*/' (choice))
  821.  
  822.           number     ('123456789'(choice))
  823.      )
  824.    )
  825.  
  826. Now input text 1+2*3+3*5  will be parsed as follows: 
  827.  
  828. expr
  829. ΓööΓöÇadd_expr
  830.   Γö£ΓöÇadd_expr
  831.   Γöé Γö£ΓöÇmult_expr
  832.   Γöé Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ1
  833.   Γöé Γö£ΓöÇadd_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ+
  834.   Γöé ΓööΓöÇmult_expr1
  835.   Γöé   ΓööΓöÇmult_expr
  836.   Γöé     Γö£ΓöÇmult_expr
  837.   Γöé     Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ2
  838.   Γöé     Γö£ΓöÇmult_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ*
  839.   Γöé     ΓööΓöÇmult_expr1
  840.   Γöé       ΓööΓöÇmult_expr
  841.   Γöé         ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ3
  842.   Γö£ΓöÇadd_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ+
  843.   ΓööΓöÇmult_expr
  844.     Γö£ΓöÇmult_expr
  845.     Γöé ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ4
  846.     Γö£ΓöÇmult_oprtΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ*
  847.     ΓööΓöÇmult_expr1
  848.       ΓööΓöÇmult_expr
  849.         ΓööΓöÇnumberΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ5
  850.  
  851.  
  852. ΓòÉΓòÉΓòÉ 3.3.2. Reduce/Reduce conflicts ΓòÉΓòÉΓòÉ
  853.  
  854. A reduce/reduce conflict occurs if there are two or more rules that apply to 
  855. the same sequence of input.  This usually indicates a serious error in the 
  856. grammar. 
  857.  
  858. For example, here is an erroneous attempt to define a sequence of zero or more 
  859. word aggregatings. 
  860.  
  861.  
  862. LR
  863.   (
  864.      NAME(SQNS_1)
  865.      TITLE('Sequences 1.')
  866.      RULES
  867.      (
  868.         sequence ( word (zero))
  869.                  ( sequence word )
  870.  
  871.         word     ('123456789'(choice))
  872.       )
  873.     )
  874.  
  875. The error is an ambiguity: there is more than one way to parse a single word 
  876. into a sequence. It could be reduced directly via the first rule. 
  877. Alternatively, nothing-at-all could be reduced into a sequence via the first 
  878. rule, and this could be combined with the word using the second rule. 
  879.  
  880. LR resolves a reduce/reduce conflict by choosing to use the rule that appears 
  881. first in the grammar, but it is very risky to rely on this. 
  882.  
  883. LR not promise a grammar of the similar kind. 
  884.  
  885. Sometimes reduce/reduce conflicts can occur that don't look warranted. 
  886.  
  887. Here is an example: 
  888.  
  889. LR
  890.   (
  891.      NAME(DEF)
  892.      TITLE('Definitions.')
  893.      RULES
  894.      (
  895.         def           ( param_spec return_spec comma )
  896.  
  897.         param_spec    ( type )
  898.                       ( name_list colon type )
  899.  
  900.         return_spec   ( type )
  901.                       ( name colon type )
  902.  
  903.         type          ( ID )
  904.  
  905.         name          ( ID )
  906.  
  907.         name_list     ( name )
  908.                       ( name comma name_list )
  909.  
  910.         comma         ( ',' )
  911.         colon         ( ':' )
  912.  
  913.         ID            ( 'abcd'(choice) )
  914.  
  915.       )
  916.     )
  917.  
  918. It would seem that this grammar can be parsed with only a single token of 
  919. look-ahead: when a param_spec  is being read, an ID  is a name if a comma or 
  920. colon follows, or a type  if another ID follows. In other words, this grammar 
  921. is LR(1). 
  922.  
  923. In this grammar, two contexts, that after an ID at the beginning of a 
  924. param_spec  and likewise at the beginning of a return_spec, are similar enough 
  925. that LR assumes they are the same. They appear similar because the same set of 
  926. rules would be active---the rule for reducing to a name  and that for reducing 
  927. to a type. LR is unable to determine at that stage of processing that the rules 
  928. would require different look-ahead tokens in the two contexts, so it makes a 
  929. single parser state for them both.  Combining the two contexts causes a 
  930. conflict later. 
  931.  
  932.  
  933. ΓòÉΓòÉΓòÉ 4. Source language grammar specification ΓòÉΓòÉΓòÉ
  934.  
  935.  A text in any language can be viewed as a string of characters chosen from 
  936. some set, or alphabet, of characters. The rules that tell us whether a string 
  937. is a valid text of the language or not are called the syntax of the language. 
  938.  
  939. Before all accordingly to LR the syntax of source language ( its grammar) must 
  940. be specified by Grammar definition language, that allows to specify any LR(k) 
  941. grammars. 
  942.  
  943.  
  944. ΓòÉΓòÉΓòÉ 4.1. Grammar definition language ΓòÉΓòÉΓòÉ
  945.  
  946. For definition of a context free grammar LR supply a special notation named as 
  947. Grammar Definition Language. 
  948.  
  949. The facilities of GDL are represented in following chapters: 
  950.  
  951. o Overall definition structure; 
  952. o Production definition; 
  953. o Nonterminal options; 
  954. o Terminal options; 
  955. o Global options; 
  956. o Comments. 
  957.  
  958.  
  959. ΓòÉΓòÉΓòÉ 4.1.1. Overall definition structure ΓòÉΓòÉΓòÉ
  960.  
  961. Each grammar definition has the following basic layout: 
  962.  
  963.  
  964. LR
  965.  (name  (LR_SQL)
  966.   title ('SQL V2R3 - Structured Query Language')
  967.   path        ('c:\mygr\')
  968.   save        (c:\mygr\prs_tab.lrs)
  969.   print       (\err\err.lr)
  970.   struct      (mygr.inc)
  971.   rules
  972.    (
  973.      *here must be placed a production definitions
  974.    )
  975.   ignore(comma dot colon double)
  976.   string(VAR INTEGER STRING)
  977.   describe (VAR( 'variable' ))
  978.  )
  979.  
  980. LR                  The grammar must start with the word LR followed by the 
  981.                     grammar definition enclosed in parenthesis.  The keywords 
  982.                     at this level are global in effect, most of them can be 
  983.                     overridden in the individual production definition. 
  984.  
  985. NAME                The name of the grammar.  This name will be used to provide 
  986.                     the default prefix for file names (*.lrs, *.str, *.n, *.prs 
  987.                     and *.lr files), and for the structures and macros used to 
  988.                     map and navigate the parse tree produced from this grammar. 
  989.  
  990. TITLE               The title of the grammar.  Used in comments generated by 
  991.                     the parser generator. 
  992.  
  993. PATH                The path to subdirectory where a results of parser 
  994.                     generating must be placed. This option is optional.If it is 
  995.                     not presented then results of parser generating is placed 
  996.                     in the default directory. 
  997.  
  998. SAVE                This option tells the parser generator where save the 
  999.                     created parsing table (*.lrs file). 
  1000.  
  1001. PRINT               This option tells the LR parser to create <<*.PRS>> file, 
  1002.                     in which the parsed text and resulting parse tree is 
  1003.                     printed. The name of the PRS-file can be defined in 
  1004.                     parenthesis. If the name of the PRS-file is not defined 
  1005.                     then the default name is used for it. 
  1006.  
  1007. STRUCT              This option  tells the parser generator to create <<*.STR>> 
  1008.                     and <<*.N>> files, which are C include files containing the 
  1009.                     macro definitions needed for semantic processing of the 
  1010.                     parse tree. The names of the STR- and N-files can be 
  1011.                     defined in parenthesis. If names of the STR- and N-files 
  1012.                     are not defined then default names are used for them. 
  1013.  
  1014. RULES               Here in parenthesis must be placed a few definitions of 
  1015.                     productions comprising the grammar of your language. 
  1016.  
  1017. DESCRIBE            Description of a nonterminal.  This description is used in 
  1018.                     formatting error messages. 
  1019.  
  1020. Here can be used any nonterminal option with brackets '()' following it. In 
  1021. these brackets must be list of nonterminals. This usage means that mentioned 
  1022. nonterminals have this option (attribute) e.g. : OPTIONAL (minus) means that 
  1023. nonterminal 'minus' will be used as 'minus (optional)' always during 
  1024. compilation of the grammar. 
  1025.  
  1026.  
  1027. ΓòÉΓòÉΓòÉ 4.1.2. Production definition ΓòÉΓòÉΓòÉ
  1028.  
  1029. Production. 
  1030.  
  1031.  
  1032. ΓòÉΓòÉΓòÉ 4.1.3. Nonterminal options ΓòÉΓòÉΓòÉ
  1033.  
  1034. As described in the previous section, the nonterminals may be followed by 
  1035. keywords in parenthesis: 
  1036.  
  1037. ZERO                This occurrence of this nonterminal may be repeated zero or 
  1038.                     more times. 
  1039.  
  1040. REPEAT              This occurrence of this nonterminal may be repeated one or 
  1041.                     more times. 
  1042.  
  1043. CHOICE              Each production for this nonterminal must consist of only 
  1044.                     one nonterminal.  These nonterminals may be selected in any 
  1045.                     order, but either zero or one times only. 
  1046.  
  1047. IGNORE              This occurrence of this nonterminal is not to be indexed in 
  1048.                     the parse tree. 
  1049.  
  1050. OPTIONAL            This occurrence of this nonterminal is optional.  This can 
  1051.                     save writing productions with the same LHS's (sometimes). 
  1052.  
  1053. SECONDARY           This nonterminal is to be tested for expansion only after 
  1054.                     all other possible non secondary nonterminals have been 
  1055.                     tried. The productions for nonterminals which have been 
  1056.                     defined as secondary may only contain terminals on the RHS. 
  1057.  
  1058. STRING              Nonterminals used to construct strings rather than parse 
  1059.                     tree entries. 
  1060.  
  1061.  
  1062. ΓòÉΓòÉΓòÉ 4.1.4. Terminal options ΓòÉΓòÉΓòÉ
  1063.  
  1064. Terminals may also be followed by keywords to provide additional information 
  1065. about their purpose: 
  1066.  
  1067. MIXED               The characters in the terminal will match text in the 
  1068.                     statement being parsed regardless of whether they are in 
  1069.                     upper or lower case. 
  1070.  
  1071.                                         'select' (mixed)
  1072.  
  1073.                     would match 
  1074.  
  1075.                                         Select
  1076.                                         SELecT
  1077.                                         seLECt
  1078.  
  1079.                     amongst others. 
  1080.  
  1081. CHOICE              The CHOICE keyword allows you to compress definitions of 
  1082.                     terminals: 
  1083.  
  1084.                                         '123456789' (choice)
  1085.  
  1086.                     is equivalent to: 
  1087.  
  1088.                                         '1'
  1089.                                         '2'
  1090.                                         '3'
  1091.                                         '4'
  1092.                                         '5'
  1093.                                         '6'
  1094.                                         '7'
  1095.                                         '8'
  1096.                                         '9'
  1097.  
  1098. NOT                 NOT behaves just like CHOICE, except all the characters not 
  1099.                     presented in the string are used to generate terminal 
  1100.                     definitions: 
  1101.  
  1102.                                         '''' (not)
  1103.  
  1104.                     Example of NOT terminal option 
  1105.  
  1106.                     Defines terminals for every character except the single 
  1107.                     quote character.  (You may think that this leads to rather 
  1108.                     a large number of terminals.  LR uses various compression 
  1109.                     techniques to overcome this potential problem.) 
  1110.  
  1111. SEQUENCE            This is the default, so you never have to use it unless you 
  1112.                     are really picky. 
  1113.  
  1114.  
  1115. ΓòÉΓòÉΓòÉ 4.1.5. Global options ΓòÉΓòÉΓòÉ
  1116.  
  1117. At level  of grammar name definition can be used any nonterminal option with 
  1118. parenthesis following it. In these parenthesis must be list of nonterminals. 
  1119. This usage means that mentioned nonterminals have this option (attribute) e.g. 
  1120. : OPTIONAL (minus) means that nonterminal 'minus' will be used as 
  1121. 'minus(optional)' during compilation of the grammar. 
  1122.  
  1123. The following global nonterminal options are available: 
  1124.  
  1125. ZERO                Nonterminals which will always be repeated zero or more 
  1126.                     times. 
  1127.  
  1128. REPEAT              Nonterminals which will always be repeated one or more 
  1129.                     times. 
  1130.  
  1131. CHOICE              Rule choices for these nonterminals can be processed zero 
  1132.                     or once each in any order. 
  1133.  
  1134. IGNORE              These nonterminals are not included in the parse tree. 
  1135.  
  1136. OPTIONAL            These nonterminals are optional. 
  1137.  
  1138. SECONDARY           These nonterminals are tried after all possible primary 
  1139.                     nonterminals. Can only contain terminals on the RHS. 
  1140.  
  1141. STRING              Nonterminals used to construct strings rather than parse 
  1142.                     tree nodes. 
  1143.  
  1144.  
  1145. ΓòÉΓòÉΓòÉ 4.1.6. Comments ΓòÉΓòÉΓòÉ
  1146.  
  1147. To place a comment into a grammar definition file the comment control character 
  1148. '*' must be used. 
  1149.  
  1150. The * comment control character allows you to place a comment into your file. 
  1151.  
  1152. The parser generator ignores any text on the same line as the comment control 
  1153. character from the * character to the end of that line including the * 
  1154. character.  Example 
  1155.  
  1156. * When the source file is compiled, the text on the
  1157. * comment line is ignored.
  1158.  
  1159.  
  1160. ΓòÉΓòÉΓòÉ 4.1.7. Grammar definition example 1 ΓòÉΓòÉΓòÉ
  1161.  
  1162. *
  1163. *   In the beginning of grammar definition file must
  1164. *            be three symbols: 'LR('
  1165. *
  1166.  
  1167. LR
  1168. (
  1169.  
  1170. *
  1171. *  After opening bracket must be set of obligatory and facultative
  1172. *  options.
  1173. *
  1174.  
  1175. *
  1176. *  Option 'NAME' : specifies names (but not extensions) of the files
  1177. *        that will be created during work of the parser.
  1178. *
  1179.  
  1180.    NAME(SAMPLE)
  1181.  
  1182. *
  1183. *   Option 'TITLE' : defines title for your grammar.
  1184. *
  1185.  
  1186.    TITLE('Sample of grammar')
  1187.  
  1188. *
  1189. *   Option 'STRUCT' : tells the parser to create
  1190. *   STR-file and N-file.
  1191. *
  1192.  
  1193.    STRUCT
  1194.  
  1195. *
  1196. *   Option 'PRINT' : tells the parser to create LR-file.
  1197. *
  1198.  
  1199.    PRINT
  1200.  
  1201. *
  1202. *   Option 'RULES' : in brackets '()' that follow this option
  1203. *   you must define your grammar using GDL.
  1204. *
  1205.  
  1206.  
  1207.    RULES
  1208.    (
  1209.  
  1210.  
  1211. *   The first <<rule>> after opening bracket '(' is assumed as
  1212. *   start nonterminal for this grammar
  1213. *   S( DECLARATION(ZERO) ASSIGN(REPEAT) )
  1214. *      Nonterminal options:
  1215. *          ZERO   -   means that previous nonterminal may repeat
  1216. *                     0, 1 or more times
  1217. *           REPEAT -   means that previous nonterminal may repeat
  1218. *                      1 or more times
  1219. *      Example:
  1220. *         S ( ASSIGN ASSIGN )
  1221. *         S ( DECLARATION DECLARATION ASSIGN )
  1222. *
  1223.  
  1224.       S                 ( ASSIGNS )
  1225.  
  1226. *
  1227. *   Here nonterminal ASSIGNS is defined two times it means that
  1228. *   this nonterminal may be reduced as
  1229. *   ( ASSIGNS ASSIGN ) or as ( ASSIGN ).
  1230. *
  1231.  
  1232.       ASSIGNS           ( ASSIGNS ASSIGN )
  1233.                         ( ASSIGN )
  1234.  
  1235.       ASSIGN            ( IDENTIFIER assign_sign E semi )
  1236.       E                 ( ADD )
  1237.                         ( SUB )
  1238.                         ( T )
  1239.       ADD               ( E plus T )
  1240.       SUB               ( E minus T )
  1241.       T                 ( MUL )
  1242.                         ( DIV )
  1243.                         ( F   )
  1244.       MUL               ( T mul F )
  1245.       DIV               ( T div F )
  1246.       F                 ( NEG )
  1247.                         ( IDENTIFIER )
  1248.                         ( FLOAT )
  1249.                         ( op E cp )
  1250.       NEG               ( minus F )
  1251.  
  1252. *
  1253. *  Nonterminal options:
  1254. *     SECONDARY - means that previous nonterminal must be reduced
  1255. *                 only when no other non-secondary nonterminals can
  1256. *                 be reduced.
  1257. *
  1258.  
  1259.       IDENTIFIER        ( ALPHA(SECONDARY) ALPHA_NUMERIC (ZERO) )
  1260.  
  1261. *
  1262. *  Nonterminal options:
  1263. *     OPTIONAL  - means that preceding nonterminal may repeat
  1264. *                       0 or 1 times.
  1265. *   Example:
  1266. *      F ( p(optional) q ) means F ( p q ) or F ( q )
  1267. *
  1268.  
  1269.       FLOAT             ( point(optional) DIGIT(repeat) EXP )
  1270.       FLOAT             ( DIGIT(repeat) point _DIGIT(zero) EXP )
  1271.       EXP               ( _e_ SIGN(optional) DIGIT(repeat) )
  1272.  
  1273. *
  1274. *   Terminal options:
  1275. *     CHOICE    - means that preceding string (enclosed in '') must be
  1276. *                 replaced with one of it's component
  1277. *     Example:
  1278. *           SIGN ('+-'(CHOICE)) means SIGN ('+') or SIGN ('-')
  1279. *
  1280.  
  1281.       SIGN              ( '+-'(CHOICE))
  1282.       ALPHA             ( '_QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'(Choice) )
  1283.       ALPHA_NUMERIC     ( '_QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789'(Choice) )
  1284.  
  1285.       minus             ( '-' )
  1286.       plus              ( '+' )
  1287.       div               ( '/' )
  1288.       mul               ( '*' )
  1289.  
  1290.       semi              ( ';' )
  1291.       DIGIT             ( '0123456789'(choice) )
  1292.       _DIGIT            ( DIGIT )
  1293.       _e_               ( 'eE'(choice) )
  1294.       point             ( '.' )
  1295.       op                ( '(' )
  1296.       cp                ( ')' )
  1297.       assign_sign       ( '=' )
  1298.  
  1299.    )
  1300.  
  1301.  
  1302. *
  1303. *  Here can be used any NONTERMINAL option with brackets '()' following
  1304. *  it. In these brackets must be list of nonterminals. This usage means
  1305. *  that mentioned nonterminals have this option (attribute)
  1306. *  e.g. : OPTIONAL (minus) means that nonterminal 'minus' will
  1307. *  be used as 'minus(optional)' during compilation of the grammar.
  1308. *
  1309.  
  1310.  
  1311.    IGNORE   ( semi op cp assign_sign minus plus mul div mod)
  1312.    STRING   ( IDENTIFIER FLOAT )
  1313.    OPTIONAL ( EXP )
  1314.  
  1315. )
  1316.  
  1317. Grammar example 1 
  1318.  
  1319.  
  1320. ΓòÉΓòÉΓòÉ <hidden> STR-file and N-file ΓòÉΓòÉΓòÉ
  1321.  
  1322. #ifndef SQNS_1_PT_INC
  1323. #define SQNS_1_PT_INC
  1324. /*
  1325. ______________________________________________________________________________
  1326. Nonterminal parse items for SQNS_1
  1327. ______________________________________________________________________________
  1328. */
  1329. typedef struct SQNS_1_PT
  1330.  {LR_PT *l;
  1331.   LR_P  *p;
  1332.   LR_PT *key[5];
  1333.  } SQNS_1_PT;
  1334. #define                     SQNS_1_alpha(_T) ((_T).l = (_T).key[0])
  1335. #define                     SQNS_1_alpha_n                      0
  1336. #define                SQNS_1_end_of_seq(_T) ((_T).l = (_T).key[1])
  1337. #define                SQNS_1_end_of_seq_n                      1
  1338. #define                      SQNS_1_item(_T) ((_T).l = (_T).key[2])
  1339. #define                      SQNS_1_item_n                      2
  1340. #define                     SQNS_1_omega(_T) ((_T).l = (_T).key[3])
  1341. #define                     SQNS_1_omega_n                      3
  1342. #define                  SQNS_1_sequence(_T) ((_T).l = (_T).key[4])
  1343. #define                  SQNS_1_sequence_n                      4
  1344. #define                           SQNS_1_n                      5
  1345.  
  1346. #endif
  1347.  
  1348. For  the grammar of a simple sequences the parser generator create following 
  1349. N-file: 
  1350.  
  1351. #ifndef SQNS_1_PT_N
  1352. #define SQNS_1_PT_N
  1353. /*
  1354. ______________________________________________________________________________
  1355. Nonterminal parse items for SQNS_1
  1356. ______________________________________________________________________________
  1357. */
  1358. typedef struct SQNS_1_PT
  1359.  {LR_PT *l;
  1360.   LR_P  *p;
  1361.   LR_PT *key[5];
  1362.  } SQNS_1_PT;
  1363.  
  1364. #define                           SQNS_1_n                      5
  1365.  
  1366. #endif
  1367.  
  1368.  
  1369. ΓòÉΓòÉΓòÉ <hidden> Parse tree for the grammar of a simple sequences ΓòÉΓòÉΓòÉ
  1370.  
  1371. For  the grammar of a simple sequences and input text abc1a2b3c. the LR parser 
  1372. create the tree: 
  1373.  
  1374. Grammar SQNS_1 on input:
  1375.  
  1376. abc1a2b3c.
  1377.  
  1378. sequence
  1379. Γö£ΓöÇalphaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇa
  1380. Γö£ΓöÇitem
  1381. Γöé Γö£ΓöÇitem
  1382. Γöé Γöé ΓööΓöÇalphaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇb
  1383. Γöé Γö£ΓöÇitem
  1384. Γöé Γöé ΓööΓöÇalphaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇc
  1385. Γöé Γö£ΓöÇitem
  1386. Γöé Γöé ΓööΓöÇomegaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ1
  1387. Γöé Γö£ΓöÇitem
  1388. Γöé Γöé ΓööΓöÇalphaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇa
  1389. Γöé Γö£ΓöÇitem
  1390. Γöé Γöé ΓööΓöÇomegaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ2
  1391. Γöé Γö£ΓöÇitem
  1392. Γöé Γöé ΓööΓöÇalphaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇb
  1393. Γöé Γö£ΓöÇitem
  1394. Γöé Γöé ΓööΓöÇomegaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ3
  1395. Γöé ΓööΓöÇitem
  1396. Γöé   ΓööΓöÇalphaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇc
  1397. ΓööΓöÇend_of_seqΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ.
  1398.  
  1399.  
  1400. ΓòÉΓòÉΓòÉ <hidden> LR-file ΓòÉΓòÉΓòÉ
  1401.  
  1402. LR Parser: SQNS_2 - Sequences 2.
  1403. Severe errors
  1404. Line 12  : 0019 Zero production in rule 'sequence(1)'
  1405.  
  1406. Nonterminals: Total of 2
  1407. Nonterminals___ Reduce  Attributes
  1408. sequence         Normal
  1409. word             Normal
  1410.  
  1411. Rules: Total of 3
  1412. Rule____________  No._____  LHS_____________  #NT_____  RHS
  1413.  
  1414. sequence                 1  sequence                 1  word(1 RO)
  1415. sequence                 2  sequence                 2  sequence(2)  word(3)
  1416.  
  1417. word                     3  word                     0  123456789(4)
  1418.  
  1419. Parse structure
  1420. LR
  1421.   NAME(SQNS_2)
  1422.     SQNS_2
  1423.   TITLE('Sequences 2.')
  1424.     'Sequences 2.'
  1425.   PATH
  1426.   STRUCT
  1427.   PRINT
  1428.   RULES
  1429.     sequence
  1430.       word (zero )
  1431.         zero
  1432.     ( sequence word )
  1433.       sequence
  1434.       word
  1435.     word     ('123456789'(choice))
  1436.       '123456789'(choice)
  1437.         choice
  1438.  
  1439.  
  1440. ΓòÉΓòÉΓòÉ <hidden> Automaton  of example 2 grammar ΓòÉΓòÉΓòÉ
  1441.  
  1442.  
  1443. LR Parser: SQNS_1 - Sequences 1.
  1444. No errors detected
  1445.  
  1446. Nonterminals: Total of 5
  1447. Nonterminals___ Reduce  Attributes
  1448. alpha            String
  1449. end_of_seq       String
  1450. item             Normal
  1451. omega            String
  1452. sequence         Normal
  1453.  
  1454. Rules: Total of 8
  1455. Rule____________  No._____  LHS_____________  #NT_____  RHS
  1456.  
  1457. alpha                    4  alpha                    0  abcd(6)
  1458.  
  1459. end_of_seq               6  end_of_seq               0  .(8)
  1460.  
  1461. item                     2  item                     1  alpha(4)
  1462. item                     3  item                     1  omega(5)
  1463.  
  1464. omega                    5  omega                    0  123456789(7)
  1465.  
  1466. sequence                 7  sequence                 2  alpha(9)  end_of_seq(10)
  1467. sequence                 1  sequence                 3  alpha(1)  item(2 RO)  end_of_seq(3)
  1468.  
  1469. States: Total of 16
  1470. Start state: 0
  1471.  
  1472. State        0 EXPANDED
  1473.   Nonterminals
  1474.     alpha(2)    sequence(1)
  1475.   Terminals 0
  1476.          3 abcd
  1477.  
  1478. State        1 EXPANDED      FINAL
  1479.  
  1480.  
  1481. State        2 EXPANDED
  1482.   Nonterminals
  1483.     alpha(7)    end_of_seq(5)    item(4)    omega(8)
  1484.   Terminals 0
  1485.          6 .
  1486.          9 123456789
  1487.         10 abcd
  1488.  
  1489. Expand rule components:  alpha(1)  alpha(9)
  1490.  
  1491.  
  1492. State        3
  1493.  
  1494.   Reduce by 0 rule alpha(4):
  1495.     From____  To______  Push  Nonterminal
  1496.            0         2     1  alpha
  1497.  
  1498.  
  1499. State        4 EXPANDED
  1500.   Nonterminals
  1501.     alpha(7)    end_of_seq(11)    item(4)    omega(14)
  1502.   Terminals 0
  1503.         12 .
  1504.         15 123456789
  1505.         16 abcd
  1506.  
  1507. Expand rule components:  item(2)
  1508.  
  1509.  
  1510. State        5 EXPANDED
  1511.  
  1512.   Reduce by 2 rule sequence(7):
  1513.     From____  To______  Push  Nonterminal
  1514.            0         1     1  sequence
  1515.  
  1516.  
  1517. Expand rule components:  end_of_seq(10)
  1518.  
  1519.  
  1520. State        6
  1521.  
  1522.   Reduce by 0 rule end_of_seq(6):
  1523.     From____  To______  Push  Nonterminal
  1524.            2         5     1  end_of_seq
  1525.  
  1526.  
  1527. State        7 EXPANDED
  1528.  
  1529.   Reduce by 1 rule item(2):
  1530.     From____  To______  Push  Nonterminal
  1531.            2         4     1  item
  1532.            4         4     0  item
  1533.  
  1534.  
  1535. Expand rule components:  alpha(4)
  1536.  
  1537.  
  1538. State        8 EXPANDED
  1539.  
  1540.   Reduce by 1 rule item(3):
  1541.     From____  To______  Push  Nonterminal
  1542.            2         4     1  item
  1543.  
  1544.  
  1545. Expand rule components:  omega(5)
  1546.  
  1547.  
  1548. State        9
  1549.  
  1550.   Reduce by 0 rule omega(5):
  1551.     From____  To______  Push  Nonterminal
  1552.            2         8     1  omega
  1553.  
  1554.  
  1555. State       10
  1556.  
  1557.   Reduce by 0 rule alpha(4):
  1558.     From____  To______  Push  Nonterminal
  1559.            2         7     1  alpha
  1560.  
  1561.  
  1562. State       11 EXPANDED
  1563.  
  1564.   Reduce by 3 rule sequence(1):
  1565.     From____  To______  Push  Nonterminal
  1566.            0         1     1  sequence
  1567.  
  1568.  
  1569. Expand rule components:  end_of_seq(3)
  1570.  
  1571.  
  1572. State       12
  1573.  
  1574.   Reduce by 0 rule end_of_seq(6):
  1575.     From____  To______  Push  Nonterminal
  1576.            4        11     1  end_of_seq
  1577.  
  1578.  
  1579. State       14 EXPANDED
  1580.  
  1581.   Reduce by 1 rule item(3):
  1582.     From____  To______  Push  Nonterminal
  1583.            4         4     0  item
  1584.  
  1585.  
  1586. Expand rule components:  omega(5)
  1587.  
  1588.  
  1589. State       15
  1590.  
  1591.   Reduce by 0 rule omega(5):
  1592.     From____  To______  Push  Nonterminal
  1593.            4        14     1  omega
  1594.  
  1595.  
  1596. State       16
  1597.  
  1598.   Reduce by 0 rule alpha(4):
  1599.     From____  To______  Push  Nonterminal
  1600.            4         7     1  alpha
  1601.  
  1602.  
  1603. Parse structure
  1604. LR
  1605.   NAME(SQNS_1)
  1606.     SQNS_1
  1607.   TITLE('Sequences 1.')
  1608.     'Sequences 1.'
  1609.   PATH
  1610.   STRUCT
  1611.   PRINT
  1612.   RULES
  1613.     sequence    ( alpha item ( zero ) end_of_seq)
  1614.       alpha
  1615.       item ( zero )
  1616.         zero
  1617.       end_of_seq
  1618.     item        (alpha)
  1619.       alpha
  1620.     (omega)
  1621.       omega
  1622.     alpha       ('abcd'(choice mixed))
  1623.       'abcd'(choice mixed)
  1624.         choice
  1625.         mixed
  1626.     omega       ('123456789'(choice))
  1627.       '123456789'(choice)
  1628.         choice
  1629.     end_of_seq  ('.')
  1630.       '.'
  1631.  
  1632.  
  1633. ΓòÉΓòÉΓòÉ <hidden> Error file of grammar of example 2 ΓòÉΓòÉΓòÉ
  1634.  
  1635. Text____
  1636. 1abc1a2b3c
  1637. !
  1638.  
  1639.  
  1640. Nonterminals expected:
  1641. alpha
  1642. sequence
  1643.  
  1644. Terminals expected:
  1645. abcd
  1646.  
  1647.  
  1648. Stack at time error was detected
  1649.        0
  1650.  
  1651.    Text: 1abc1a2b3c
  1652.  
  1653.  
  1654. ΓòÉΓòÉΓòÉ 5. LR-parsing table construction ΓòÉΓòÉΓòÉ
  1655.  
  1656. When the grammar definition is written, LR-parsing table my be generated by: 
  1657.  
  1658. o Usage of the parser generator within WorkFrame/2; 
  1659.  
  1660. o Parser generator call from command line; 
  1661.  
  1662. o Parser generator call from user program. 
  1663.  
  1664.  
  1665. ΓòÉΓòÉΓòÉ 5.1. Usage of the parser generator within WorkFrame/2 ΓòÉΓòÉΓòÉ
  1666.  
  1667. To use the parser generator within  WorkFrame/2 your must do following steps: 
  1668.  
  1669.  1. To create a make-project: 
  1670.  
  1671.     a. Set the project field 'Directory' with path of your grammar file; 
  1672.  
  1673.     b. Set the field 'Target file name' with name of LRS-file ( file where 
  1674.        parsing table will be placed ) <<NAME_OF_GRAMMAR>>.lrs; 
  1675.  
  1676.     c. Set the project field 'Make file name' with file name of makefile 
  1677.        similar to makefile in example. 
  1678.  
  1679.  2. Edit variables of this makefile LRP_DIR, TEXT, GR to tune it up for your 
  1680.     purposes. 
  1681.  
  1682. Note:  Results of making this project are the same as the results of working 
  1683.        <command line version of LRP>. 
  1684.  
  1685.  
  1686. ΓòÉΓòÉΓòÉ 5.2. Parser generator call from command line ΓòÉΓòÉΓòÉ
  1687.  
  1688. After a syntax of input language have been described with GDL, it is necessary 
  1689. to create parsing table that corresponds to the given grammar. 
  1690.  
  1691. To create parsing-table using command line, you must type following command: 
  1692.  
  1693. SYNTAX: 
  1694.                          lrp.exe grammar_file 
  1695.  
  1696. PARAMETERS: 
  1697.                          "grammar_file" is a file containing GDL description of 
  1698.                          grammar. The format of the name of the file is 
  1699.                          <<NAME>> .GR. 
  1700.  
  1701. EFFECT: 
  1702.                          If errors have not been detected, The parser generator 
  1703.                          creates parsing-table that will be written to 
  1704.                          <<NAME>> .LRS, a file  containing definition of NPS 
  1705.                          and macros corresponding to the given grammar that 
  1706.                          named <<NAME>> .STR ( a file  <<NAME>> .N (that is 
  1707.                          also created) is subset of  <<NAME>> .STR and contains 
  1708.                          only the definition of structure of NPS and constant 
  1709.                          <<NAME>> _n that means number of nonterminals) and a 
  1710.                          file named  <<NAME>> .LR that contains protocol of 
  1711.                          parsing-table construction and detected errors. 
  1712.  
  1713.  
  1714. ΓòÉΓòÉΓòÉ 5.3. Parser generator call from user program ΓòÉΓòÉΓòÉ
  1715.  
  1716. Here described two functions that can be used for creation of compiler of 
  1717. grammars (such as LRP.EXE): 
  1718.  
  1719. lr_open   Prepare a grammar for use by the parser; 
  1720. lr_free   Release the results of LR-parsing table construction. 
  1721.  
  1722.  
  1723. ΓòÉΓòÉΓòÉ 5.3.1. lr_open    Prepare a grammar for use by the parser ΓòÉΓòÉΓòÉ
  1724.  
  1725.  SYNTAX: 
  1726.                      void lr_open (char *NAME, char *grammar, LR **Lr); 
  1727. PARAMETERS: 
  1728.  
  1729.     char *NAME 
  1730.                        Name of grammar (in case the keyword NAME() was omitted 
  1731.                        in grammar definition). 
  1732.    char *grammar 
  1733.                        String that contains text of grammar definition. 
  1734.    LR  **Lr 
  1735.                        Pointer to pointer to LR-parsing table (the pointer to 
  1736.                        created LR-parsing table is a procedure output). 
  1737.                        'lr_open' allocates memory for it in itself. You can 
  1738.                        release memory by  lr_free 
  1739. EFFECT: 
  1740.  
  1741.     1. Builds LR-parsing table using grammar definition 'grammar'. 
  1742.  
  1743.     2. Save condensed version of LR-parsing table in  <<NAME>> .lrs if no 
  1744.        errors occurred (grammar.lrs if there was text "grammar" in NAME). 
  1745.  
  1746.     3. Creates <<NAME>>.str and <<NAME>>.n if necessary. 
  1747. RETURN: 
  1748.                     Nothing. 
  1749.  
  1750.  
  1751. ΓòÉΓòÉΓòÉ 5.3.2. lr_free    Release the results of LR-parsing table construction. ΓòÉΓòÉΓòÉ
  1752.  
  1753. Release the results of LR-parsing table construction. 
  1754.  
  1755. SYNTAX: 
  1756.                     void lr_free (LR  *lr); 
  1757. PARAMETERS: 
  1758.  
  1759.     LR *lr 
  1760.                        Pointer to LR-parsing table. 
  1761. EFFECT: 
  1762.                     Releases memory allocated by lr_open 
  1763. RETURN: 
  1764.                     Nothing 
  1765.  
  1766.  
  1767. ΓòÉΓòÉΓòÉ 5.4. Input data for parser generator ΓòÉΓòÉΓòÉ
  1768.  
  1769. Input data for parser generator are contained in GR file in which user defines 
  1770. the grammar. 
  1771.  
  1772.  
  1773. ΓòÉΓòÉΓòÉ 5.5. Output of parser generator ΓòÉΓòÉΓòÉ
  1774.  
  1775. o Parsing table file; 
  1776. o N-file and STR-file; 
  1777. o Error message file. 
  1778. o Automaton description file. 
  1779.  
  1780.  
  1781. ΓòÉΓòÉΓòÉ 5.5.1. Parsing table file ΓòÉΓòÉΓòÉ
  1782.  
  1783. The result of compiling grammar definition written on GDL is parsing table 
  1784. file. This file is a binary file. The compiled grammar presented as 
  1785. deterministic finite automaton in this file. 
  1786.  
  1787. The name of parsing table file can be defined in grammar definition (e.g. 
  1788. SAVE('PTF.BIN')) but if you ommited global option SAVE in the grammar 
  1789. definition then the parsing table file name is constructed from the name (not 
  1790. title) of the grammar and extension '.LRS'. 
  1791.  
  1792. The parsing table file is used during source text parsing. 
  1793.  
  1794.  
  1795. ΓòÉΓòÉΓòÉ 5.5.2. N-file and STR-file ΓòÉΓòÉΓòÉ
  1796.  
  1797. These files are created by parser generator if an overall option 'STRUCT' was 
  1798. occurred in the grammar definition file. 
  1799.  
  1800. The files contain a few C-structures, C-macros and C-constants that allow to 
  1801. write a program that will process a parse trees. 
  1802.  
  1803. Here <<NAME_OF_GRAMMAR>> may be considered as a macro that defines the grammar 
  1804. name and <<NAME_OF_NONTERMINAL>> as a macro that defines the name of a 
  1805. nonterminal of the defined grammar. 
  1806.  
  1807. Structures: 
  1808.  
  1809.    struct <<NAME_OF_GRAMMAR>>_PT 
  1810.                        The nonterminal pointer set for the defined grammar. 
  1811.  
  1812.       Fields: 
  1813.  
  1814.          LR_PT *l 
  1815.                              Pointer to last selected node of parse tree. 
  1816.  
  1817.          LR_P  *p 
  1818.                              pointer to parse results. 
  1819.  
  1820.          LR_PT *key[<<NAME_OF_GRAMMAR>>_n] 
  1821.                              Set of pointers to parse tree nodes 
  1822.                              (nonterminals). 
  1823.  
  1824.                        Note:  The structure is almost equal to LRX_PT, so all 
  1825.                        macros which work with LRX_PT will work with 
  1826.                        <<NAME_OF_GRAMMAR>>_PT. 
  1827.  
  1828.    Constants: 
  1829.  
  1830.       <<NAME_OF_GRAMMAR>>_n 
  1831.                           number of nonterminals. 
  1832.  
  1833.       <<NAME_OF_GRAMMAR>>_<<NAME_OF_NONTERMINAL>>_n 
  1834.                           number of nonterminal named <<NAME_OF_NONTERMINAL>>. 
  1835.  
  1836.    Macros: 
  1837.  
  1838.       <<NAME_OF_GRAMMAR>>_<<NAME_OF_NONTERMINAL>>(<<NPS>>) 
  1839.                           Select from <<NPS>> pointer to node contained in it 
  1840.                           at key[<<NAME_OF_NONTERMINAL>>_n] and set l = this 
  1841.                           value and return the value. 
  1842.  
  1843. The difference N-file  from STR-file: 
  1844.  
  1845. N-file does not contain constants <<NAME_OF_GRAMMAR>>_<<NAME_OF_NONTERMINAL>>_n 
  1846. and macros <<NAME_OF_GRAMMAR>>_<<NAME_OF_NONTERMINAL>>. 
  1847.  
  1848. For  grammar of the example 2  the parser generator create following STR-file 
  1849. and N-file 
  1850.  
  1851.  
  1852. ΓòÉΓòÉΓòÉ 5.5.3. Error message file ΓòÉΓòÉΓòÉ
  1853.  
  1854. Any errors that were detected during compilation of grammar are placed in LR 
  1855. file. 
  1856.  
  1857. See Error message file of the parser generator . 
  1858.  
  1859. Error message format, Error explanation, Error removal. 
  1860.  
  1861.  
  1862. ΓòÉΓòÉΓòÉ 5.5.4. Automaton description file ΓòÉΓòÉΓòÉ
  1863.  
  1864. An automaton description file has name of the grammar from which it was created 
  1865. and '.LR' extension. In this file the deterministic finite automaton 
  1866. description that corresponds to compiled grammar is stored. In this file are 
  1867. listed : 
  1868.  
  1869. o all nonterminals of grammar, 
  1870.  
  1871. o all states of the deterministic finite automaton, 
  1872.  
  1873. o all reduces that are used for transition from one state to another, 
  1874.  
  1875. o all operations with nonterminal stack and parse structure of grammar. 
  1876.  
  1877. See Automaton description file example┬╖ 
  1878.  
  1879.  
  1880. ΓòÉΓòÉΓòÉ 5.6. Parser generator error message list ΓòÉΓòÉΓòÉ
  1881.  
  1882. During parsing table construction the parser generator analyses input grammar 
  1883. definition and reports all detected errors. Reported message matches one of 
  1884. following kinds: 
  1885.  
  1886. o Severe errors; 
  1887. o Informational  messages. 
  1888.  
  1889. Any error message consists of error explanation and the following elements used 
  1890. to locate an error in source grammar definition: 
  1891.  
  1892. Line number 
  1893.                     Line number of grammar definition text where the reported 
  1894.                     error is detected. 
  1895. Global 
  1896.                     Detected error concerns the grammar definition entirely. 
  1897. Terminal designator (<<TD>>) 
  1898.                     The terminal itself as terminal designator is used. 
  1899. Nonterminal designator (<<NTD>>) 
  1900.                     Nonterminal designator consists of the nonterminal name 
  1901.                     followed by a number in parenthesis. 
  1902. Terminal option designator  (<<TOD>>) 
  1903.                     Terminal option itself as terminal designator is used. 
  1904. Nonterminal option designator (<<NTOD>>) 
  1905.                     Nonterminal option itself as nonterminal designator is 
  1906.                     used. 
  1907. Rule designator (<<RD>>) 
  1908.                     Rule designator consists of the nonterminal name followed 
  1909.                     by a number in parenthesis. 
  1910. State designators (<<SD>>) 
  1911.                     State designator is a number. 
  1912. String designators (<<STRD>>) 
  1913.                     String itself as string designator is used. 
  1914.  
  1915. o  S E V E R E  E R R O R S 
  1916.  
  1917.    0001 Closing parentheses required in grammar source. 
  1918.    0002 Closing parenthesis ignored. 
  1919.    0003 Closing quote assumed. 
  1920.    0004 NAME missing. 
  1921.    0005 RULES missing. 
  1922.    0006 No start symbol. 
  1923.    0007 Start rule is a substring <<RD>>. 
  1924.    0008 Unable to save. 
  1925.    0009 Invalid terminal option <<TOD>> for terminal <<TD>>. 
  1926.    0010 Invalid nonterminal option <<NTOD>> for nonterminal <<NTD>>. 
  1927.    0011 Secondary rule <<RD>> contains a nonterminal. 
  1928.    0012 Rule <<RD>> specifies <<NTD>> as a secondary nonterminal, but <<NTD>> 
  1929.    contains a nonterminal. 
  1930.    0013 Undefined nonterminal <<NTD>>. 
  1931.    0010 Invalid nonterminal option <<NTOD>>. 
  1932.    0014 String <<NTD>> over string <<NTD>> in rule <<RD>>. 
  1933.    0015 Substring <<NTD>> over string <<NTD>> in rule <<RD>>. 
  1934.    0016 Normal <<NTD>> over substring <<NTD>> in rule <<RD>>. 
  1935.    0017 Reduce <<RD>> reduce <<RD>> at state <<SD>>. 
  1936.    0018 Mixed rule <<RD>>. 
  1937.    0019 Zero production in rule <<RD>>. 
  1938.    0020 Re-use of nonterminal <<NTD>> in rule <<RD>>. 
  1939.    0022 'Ignore' in definition of nonterminal <<NTD>> in rule <<RD>> conflicts 
  1940.    with 'No Ignore' in rule <<RD>>. 
  1941.    0024 Unable to locate next state from state <<SD>> on <<RD>> in rule <<RD>>. 
  1942.    0026 Terminal symbol overlap on <<RD>> in rule <<RD>> which affects state 
  1943.    <<SD>>. 
  1944.  
  1945. o  I N F O R M A T I O N A L  M E S S A G E S 
  1946.  
  1947.    0027 TITLE missing. 
  1948.    0028 Unused nonterminal <<NTD>>. 
  1949.    0029 Undefined optional <<NTD>>. 
  1950.    0030 Undefined secondary <<NTD>>. 
  1951.    0031 Undefined string <<NTD>>. 
  1952.    0032 Undefined zero <<NTD>>. 
  1953.    0033 Undefined repeat <<NTD>>. 
  1954.    0034 Undefined choice <<NTD>>. 
  1955.    0035 Undefined ignore <<NTD>>. 
  1956.    0037 Reduce-shift conflict from state <<SD>>, shift text <<STRD>> or reduce 
  1957.    by <<RD>>. 
  1958.  
  1959.  
  1960. ΓòÉΓòÉΓòÉ 6. Error messages of the parser generator ΓòÉΓòÉΓòÉ
  1961.  
  1962. Any errors that were detected during compilation of grammar are placed in LR 
  1963. file. 
  1964.  
  1965. See Error message file of the parser generator . 
  1966.  
  1967. Error message format, Error explanation, Error removal. 
  1968.  
  1969.  
  1970. ΓòÉΓòÉΓòÉ 6.1. Error N 0001 ΓòÉΓòÉΓòÉ
  1971.  
  1972. Error message format: 
  1973.                               L: 0001 Closing parenthesis required in grammar 
  1974.                               definition. 
  1975. Error explanation: 
  1976.                               There is opening parenthesis but no closing 
  1977.                               parenthesis for the opening parenthesis in the 
  1978.                               grammar definition. 
  1979. Error removal: 
  1980.                               Find place where must be the closing parenthesis 
  1981.                               for the opening parenthesis and insert closing 
  1982.                               parenthesis there. 
  1983. Error example: 
  1984.  
  1985.                                                             LR
  1986.                                                                 (
  1987.                                                                   NAME('E0001')
  1988.                                                                   RULES
  1989.                                                                     (
  1990.                                                                       S('a')
  1991.                                                                     )
  1992.  
  1993.  
  1994. ΓòÉΓòÉΓòÉ 6.2. Error N 0002 ΓòÉΓòÉΓòÉ
  1995.  
  1996. Error message format: 
  1997.                          L: 0002 Closing parenthesis ignored. 
  1998.  
  1999. Error explanation: 
  2000.                          There is superfluous closing parenthesis in the 
  2001.                          grammar definition. 
  2002.  
  2003. Error removal: 
  2004.                          Delete the superfluous closing parenthesis. 
  2005.                          (Check the grammar definition very carefully because 
  2006.                          this error usually invoked by careless grammar 
  2007.                          creation.) 
  2008.  
  2009. Error example: 
  2010.  
  2011.                                                   LR
  2012.                                                   (
  2013.                                                    NAME ('E0002')
  2014.                                                    RULES
  2015.                                                    (
  2016.                                                     S( ''a' )
  2017.                                                    )
  2018.                                                   ))
  2019.  
  2020.  
  2021. ΓòÉΓòÉΓòÉ 6.3. Error N 0003 ΓòÉΓòÉΓòÉ
  2022.  
  2023. Error message format: 
  2024.                          L: 0003 Closing quote assumed. 
  2025.  
  2026. Error explanation: 
  2027.                           You have missed closing quote somewhere. 
  2028.  
  2029. Error removal: 
  2030.                           Locate error and insert closing quote. 
  2031.  
  2032. Error example: 
  2033.  
  2034.                                                   LR
  2035.                                                   (
  2036.                                                    NAME ('E0002')
  2037.                                                    RULES
  2038.                                                    (
  2039.                                                     S( 'a )
  2040.                                                    )
  2041.                                                   )
  2042.  
  2043.  
  2044. ΓòÉΓòÉΓòÉ 6.4. Error N 0004 ΓòÉΓòÉΓòÉ
  2045.  
  2046. Error message format: 
  2047.                          G: 0004 NAME missing. 
  2048.  
  2049. Error explanation: 
  2050.                          You missed option <<NAME>> in the grammar definition. 
  2051.                          Option <<NAME>>> must be in the grammar definition. 
  2052.  
  2053. Error removal: 
  2054.                          Insert Option <<NAME>> in the grammar definition. 
  2055.  
  2056. Error example: 
  2057.  
  2058.                                                   LR(
  2059.                                                      RULES
  2060.                                                       (
  2061.                                                        * NAME('E0004')
  2062.                                                          S('a')
  2063.                                                       )
  2064.                                                     )
  2065.  
  2066.  
  2067. ΓòÉΓòÉΓòÉ 6.5. Error N 0005 ΓòÉΓòÉΓòÉ
  2068.  
  2069. Error message format: 
  2070.                          G: 0005 RULES missing. 
  2071.  
  2072. Error explanation: 
  2073.                          You missed option RULES in the grammar definition. 
  2074.  
  2075. Error removal: 
  2076.                          Insert option RULES in the grammar definition 
  2077.  
  2078. Error example: 
  2079.  
  2080.                                                   LR(
  2081.                                                    NAME ('E005')
  2082.                                                     )
  2083.  
  2084.  
  2085. ΓòÉΓòÉΓòÉ 6.6. Error N 0006 ΓòÉΓòÉΓòÉ
  2086.  
  2087. Error message format: 
  2088.                          G: 0006 No start symbol. 
  2089.  
  2090. Error explanation: 
  2091.                          Your RULES option is empty!!! You MUST have at least 
  2092.                          one rule!!! 
  2093.  
  2094. Error removal: 
  2095.                          Add rules in your <<RULES>> option. 
  2096.  
  2097. Error example: 
  2098.  
  2099.                                                   LR(
  2100.                                                    NAME('E0006')
  2101.                                                    RULES
  2102.                                                         (
  2103.                                                         )
  2104.                                                      )
  2105.  
  2106.  
  2107. ΓòÉΓòÉΓòÉ 6.7. Error N 0007 ΓòÉΓòÉΓòÉ
  2108.  
  2109. Error message format: 
  2110.                          L: 0007 Start rule is a substring <<RD>>. 
  2111.  
  2112. Error explanation: 
  2113.                          Your <<start rule>> is a substring in some other 
  2114.                          nonterminal. 
  2115.  
  2116. Error removal: 
  2117.                          Review your grammar!!! It is incorrect now. 
  2118.  
  2119. Error example: 
  2120.  
  2121.                                                   LR
  2122.                                                   (
  2123.                                                    NAME('E0007')
  2124.                                                    RULES
  2125.                                                    (
  2126.                                                     S('a')
  2127.                                                     A( S B )
  2128.                                                     B('s')
  2129.                                                    )
  2130.                                                    STRING( A )
  2131.                                                   )
  2132.  
  2133.  
  2134. ΓòÉΓòÉΓòÉ 6.8. Error N 0008 ΓòÉΓòÉΓòÉ
  2135.  
  2136. Error message format: 
  2137.                          G: 0008 Unable to save. 
  2138.  
  2139. Error explanation: 
  2140.                          There was OS/2 error during saving some of output 
  2141.                          files. 
  2142.  
  2143. Error removal: 
  2144.                          Free more space on your destination drive. If it will 
  2145.                          not help then contact <<Transcedental Automation>> or 
  2146.                          <<IBM>>. 
  2147.  
  2148. Error example: 
  2149.                          Make your minidisk write-protected, insert it in drive 
  2150.                          A and redirect all your output files to A. 
  2151.  
  2152.  
  2153. ΓòÉΓòÉΓòÉ 6.9. Error N 0009 ΓòÉΓòÉΓòÉ
  2154.  
  2155. Error message format: 
  2156.                          L: 0009 Invalid terminal option <<TOD>> for terminal 
  2157.                          <<TD>>. 
  2158.  
  2159. Error explanation: 
  2160.                          You use terminal with invalid option 
  2161.  
  2162. Error removal: 
  2163.                          Remove the option from terminal. 
  2164.                          (This error is usually caused by misprints and 
  2165.                          misthinkings). 
  2166.  
  2167. Error example: 
  2168.  
  2169.                                                   LR
  2170.                                                   (
  2171.                                                     name(E009)
  2172.                                                     TITLE('E009')
  2173.                                                     print
  2174.                                                     rules
  2175.                                                     (
  2176.                                                       S ('a'(string))
  2177.                                                     )
  2178.                                                   )
  2179.  
  2180.  
  2181. ΓòÉΓòÉΓòÉ 6.10. Error N 0010 ΓòÉΓòÉΓòÉ
  2182.  
  2183. Error message format: 
  2184.                          L: 0010 Invalid nonterminal option <<NTOD>> for 
  2185.                          nonterminal <<NTD>>. 
  2186.  
  2187. Error explanation: 
  2188.                          You use nonterminal with invalid option. 
  2189.  
  2190. Error removal: 
  2191.                          Remove the option from nonterminal. 
  2192.                          (This error is usually caused by misprints and 
  2193.                          misthinkings) 
  2194.  
  2195. Error example: 
  2196.  
  2197.                                                   LR
  2198.                                                   (
  2199.                                                     NAME(E0010)
  2200.                                                     TITLE('E0010')
  2201.                                                     RULES
  2202.                                                     (
  2203.                                                       S            (A(mixed))
  2204.                                                       A            ( B )
  2205.                                                       B            ('a')
  2206.                                                     )
  2207.                                                   )
  2208.  
  2209.  
  2210. ΓòÉΓòÉΓòÉ 6.11. Error N 0011 ΓòÉΓòÉΓòÉ
  2211.  
  2212. Error message format: 
  2213.                          L: 0011 Secondary rule <<RD>> contains a nonterminal. 
  2214.  
  2215. Error explanation: 
  2216.                           Secondary rule contains a nonterminal. 
  2217.  
  2218. Error removal: 
  2219.                           Rewrite rule changing nonterminals into terminals or 
  2220.                          delete option secondary. 
  2221.  
  2222. Error example: 
  2223.  
  2224.                                                   LR
  2225.                                                   (
  2226.                                                     name(E0011)
  2227.                                                     TITLE('E0011')
  2228.                                                     print
  2229.                                                     rules
  2230.                                                     (
  2231.                                                       S            (R A)
  2232.                                                       R            (A)
  2233.                                                       A            ('g')
  2234.                                                     )
  2235.                                                     secondary(R)
  2236.                                                   )
  2237.  
  2238.  
  2239. ΓòÉΓòÉΓòÉ 6.12. Error N 0012 ΓòÉΓòÉΓòÉ
  2240.  
  2241. Error message format: 
  2242.                          L: 0012 Rule <<RD>> specifies <<NTD>> as a secondary 
  2243.                          nonterminal,but <<NTD>> contains a nonterminal. 
  2244.  
  2245. Error explanation: 
  2246.                           Rule <<RD>> specifies <<NTD>> as a secondary 
  2247.                          nonterminal,but <<NTD>> contains a nonterminal. 
  2248.  
  2249. Error removal: 
  2250.                           Rewrite rule changing nonterminals into terminals or 
  2251.                          delete option secondary. 
  2252.  
  2253. Error example: 
  2254.  
  2255.                                                   LR
  2256.                                                   (
  2257.                                                     name(E0012)
  2258.                                                     TITLE('E0012')
  2259.                                                     print
  2260.                                                     rules
  2261.                                                     (
  2262.                                                       S            (R(secondary) A)
  2263.                                                       R            (A)
  2264.                                                       A            ('g')
  2265.                                                     )
  2266.                                                   )
  2267.  
  2268.  
  2269. ΓòÉΓòÉΓòÉ 6.13. Error N 0013 ΓòÉΓòÉΓòÉ
  2270.  
  2271. Error message format: 
  2272.                          L: 0013 Undefined nonterminal <<NTD>>. 
  2273.  
  2274. Error explanation: 
  2275.                          You have not defined nonterminal <<NTD>>, but have 
  2276.                          used it somewhere. 
  2277.  
  2278. Error removal: 
  2279.                          Define nonterminal <<NTD>>. 
  2280.  
  2281. Error example: 
  2282.  
  2283.                                                   LR
  2284.                                                   (
  2285.                                                     name(E0013)
  2286.                                                     TITLE('E0013')
  2287.                                                     print
  2288.                                                     rules
  2289.                                                     (
  2290.                                                       S            (R)
  2291.                                                     )
  2292.                                                   )
  2293.  
  2294.  
  2295. ΓòÉΓòÉΓòÉ 6.14. Error N 0014 ΓòÉΓòÉΓòÉ
  2296.  
  2297. Error message format: 
  2298.                          L: 0014 String <<NTD1>> over string <<NTD2>> in rule 
  2299.                          <<RD>>. 
  2300.  
  2301. Error explanation: 
  2302.                          In the grammar definition there is nonterminal that is 
  2303.                          defined as STRING and definition of this nonterminal 
  2304.                          there is one or more nonterminals that are defined as 
  2305.                          string(s) too. 
  2306.  
  2307. Error removal: 
  2308.                          Review and reedit your grammar to avoid this conflict. 
  2309.                          May be removing of STRING qualifier will solve the 
  2310.                          problem. Or may be you must create a copy of <<NTD2>> 
  2311.                          under unique name, then remove qualifier STRING from 
  2312.                          the copy and rename <<NTD2>> in rule <<RD>> to the 
  2313.                          unique name of the copy. 
  2314.  
  2315. Error example: 
  2316.                          Here string A over string B in rule A. 
  2317.  
  2318.                                                   LR
  2319.                                                   (
  2320.                                                     name(E0014)
  2321.                                                     TITLE('E0014')
  2322.                                                     print
  2323.                                                     rules
  2324.                                                     (
  2325.                                                       S (A)
  2326.                                                       A (C B)
  2327.                                                       B (C)
  2328.                                                       C ('c')
  2329.                                                     )
  2330.                                                     string (A B)
  2331.                                                   )
  2332.  
  2333.  
  2334. ΓòÉΓòÉΓòÉ 6.15. Error N 0015 ΓòÉΓòÉΓòÉ
  2335.  
  2336. Error message format: 
  2337.                          L: 0015 Substring <<NTD1>> over string <<NTD2>> in 
  2338.                          rule <<RD>>. 
  2339.  
  2340. Error explanation: 
  2341.                          In rule <<RD>> of the grammar definition there is 
  2342.                          nonterminal in <<RHS>> and this nonterminal is STRING. 
  2343.                          But rule <<RD>> is SUBSTRING (it is used in <<RHS>> of 
  2344.                          a rule that have been defined as STRING). 
  2345.  
  2346. Error removal: 
  2347.                          There are some ways to solve the problem. You can 
  2348.                          simply remove STRING qualifier from <<NTD2>>. You can 
  2349.                          create a copy of definition of nonterminal <<NTD2>> 
  2350.                          with unique name and then rename <<NTD2>> in rule 
  2351.                          <<RD>> to the unique name of the copy. 
  2352.  
  2353. Error example: 
  2354.                          Here is substring D over string B in rule D 
  2355.  
  2356.                                                   LR
  2357.                                                   (
  2358.                                                     name(E0015)
  2359.                                                     TITLE('E0015')
  2360.                                                     print
  2361.                                                     rules
  2362.                                                     (
  2363.                                                       S(A)
  2364.                                                       A(C D)
  2365.                                                       D(B)
  2366.                                                       B(C)
  2367.                                                       C('z')
  2368.                                                     )
  2369.                                                     string (A B)
  2370.                                                   )
  2371.  
  2372.  
  2373. ΓòÉΓòÉΓòÉ 6.16. Error N 0016 ΓòÉΓòÉΓòÉ
  2374.  
  2375. Error message format: 
  2376.                          L: 0016 Normal <<NTD1>> over substring <<NTD2>> in 
  2377.                          rule <<RD>>. 
  2378.  
  2379. Error explanation: 
  2380.                          In rule <<RD>> there is nonterminal that has been 
  2381.                          defined as part of a nonterminal that has been defined 
  2382.                          as STRING, and this(first) nonterminal has been used 
  2383.                          in <<RHS>> of nonSTRING nonterminal too. 
  2384.  
  2385. Error removal: 
  2386.                          You can simply remove STRING qualifier from the 
  2387.                          nonterminal in which <<NTD2>> defined and so <<NTD2>> 
  2388.                          no longer will be a substring. You can review your 
  2389.                          grammar carefully(it is most likely your grammar is 
  2390.                          incorrect). You can create a copy with unique name of 
  2391.                          <<NTD2>> and rename <<NTD2>> in rule <<RD>> to the 
  2392.                          unique name of the copy. 
  2393.  
  2394. Error example: 
  2395.                          Here is normal B over substring D in rule B 
  2396.  
  2397.                                                   LR
  2398.                                                   (
  2399.                                                     name(E0016)
  2400.                                                     TITLE('E0016')
  2401.                                                     print
  2402.                                                     rules
  2403.                                                     (
  2404.                                                       S(A B)
  2405.                                                       A(C D)
  2406.                                                       D('s')
  2407.                                                       B(D)
  2408.                                                       C('z')
  2409.                                                     )
  2410.                                                     string (A)
  2411.                                                   )
  2412.  
  2413.  
  2414. ΓòÉΓòÉΓòÉ 6.17. Error N 0017 ΓòÉΓòÉΓòÉ
  2415.  
  2416. Error message format: 
  2417.                          L: 0017 Reduce <<RD1>> reduce <<RD2>> at state <<SD>>. 
  2418.  
  2419. Error explanation: 
  2420.                          It is not clear what to reduce from state <<SD>>. 
  2421.  
  2422. Error removal: 
  2423.                          Review your grammar very carefully(it is most likely 
  2424.                          your grammar is incorrect) 
  2425.  
  2426. Error example: 
  2427.                          Here it is not clear what to reduce from start state: 
  2428.                          A or B. LR can reduce A as well as B and it has not 
  2429.                          been given information what it must do. 
  2430.  
  2431.                                                   LR
  2432.                                                   (
  2433.                                                     name(E0017)
  2434.                                                     TITLE('E0017')
  2435.                                                     print
  2436.                                                     rules
  2437.                                                     (
  2438.                                                       S(A)
  2439.                                                        (B)
  2440.                                                       A('a')
  2441.                                                       B('a')
  2442.                                                     )
  2443.                                                   )
  2444.  
  2445.  
  2446. ΓòÉΓòÉΓòÉ 6.18. Error N 0018 ΓòÉΓòÉΓòÉ
  2447.  
  2448. Error message format: 
  2449.                          L: 0018 Mixed rule <<RD>>. 
  2450.  
  2451. Error explanation: 
  2452.                          In <<RHS>> of rule <<RD>> nonterminals used along with 
  2453.                          terminals. 
  2454.  
  2455. Error removal: 
  2456.                          Create nonterminals that consist of one terminal from 
  2457.                          the rule <<RD>>. E.g. in the example you can create 
  2458.                          nonterminal LNT ('E'). And replace S(L 'L') with S(L 
  2459.                          LNT). 
  2460.  
  2461. Error example: 
  2462.  
  2463.                                                   LR
  2464.                                                   (
  2465.                                                     name(E0018)
  2466.                                                     TITLE('E0018')
  2467.                                                     print
  2468.                                                     rules
  2469.                                                     (
  2470.                                                       S(L 'L')
  2471.                                                       L('E')
  2472.                                                     )
  2473.                                                   )
  2474.  
  2475.  
  2476. ΓòÉΓòÉΓòÉ 6.19. Error N 0019 ΓòÉΓòÉΓòÉ
  2477.  
  2478. Error message format: 
  2479.                          L: 0019 Zero production in rule <<RD>>. 
  2480.  
  2481. Error explanation: 
  2482.                          It is clear from the grammar definition that the rule 
  2483.                          <<RD>> can be empty (empty input string can be reduced 
  2484.                          by this rule and so empty input string can be reduced 
  2485.                          by example grammar to A A ... infinity times.) 
  2486.  
  2487. Error removal: 
  2488.                          Review your grammar carefully (it is most likely your 
  2489.                          grammar is incorrect) 
  2490.  
  2491. Error example: 
  2492.  
  2493.                                                   LR
  2494.                                                   (
  2495.                                                     name(E0019)
  2496.                                                     TITLE('E0019')
  2497.                                                     print
  2498.                                                     rules
  2499.                                                     (
  2500.                                                       S(A(optional))
  2501.                                                       A('a')
  2502.                                                     )
  2503.                                                   )
  2504.  
  2505.  
  2506. ΓòÉΓòÉΓòÉ 6.20. Error N 0020 ΓòÉΓòÉΓòÉ
  2507.  
  2508. Error message format: 
  2509.                          L: 0020 Re-use of nonterminal <<NTD>> in rule <<RD>>. 
  2510.  
  2511. Error explanation: 
  2512.                          The nonterminal <<NTD>> is occurred two times in 
  2513.                          <<RHS>> in rule <<RD>>. 
  2514.  
  2515. Error removal: 
  2516.                          There are many ways to solve the problem. You can make 
  2517.                          a copy of <<NTD>> with unique name and rename the 
  2518.                          second occurrence of <<NYD>> in <<RD>> to the unique 
  2519.                          name of copy. 
  2520.  
  2521. Error example: 
  2522.  
  2523.                                                   LR
  2524.                                                   (NAME(E0020)
  2525.                                                    TITLE(E0020)
  2526.                                                    PRINT
  2527.                                                    RULES
  2528.                                                    (S (A A)
  2529.                                                     A ('a')
  2530.                                                    )
  2531.                                                   )
  2532.  
  2533.  
  2534. ΓòÉΓòÉΓòÉ 6.21. Error N 0022 ΓòÉΓòÉΓòÉ
  2535.  
  2536. Error message format: 
  2537.                          L: 0022 'Ignore' in definition of nonterminal <<NTD>> 
  2538.                          in rule <<RD1>> conflicts with 'No Ignore' in rule 
  2539.                          <<RD2>>. 
  2540.  
  2541. Error explanation: 
  2542.                          The nonterminal <<NTD>> is marked with IGNORE in rule 
  2543.                          <<RD1>> and with NOIGNORE in rule <<RD2>>. It is not 
  2544.                          clear does <<NTD>> marked with IGNORE or not. 
  2545.  
  2546. Error removal: 
  2547.                          Make decision and remove one of the markings. 
  2548.  
  2549. Error example: 
  2550.  
  2551.                                                   LR
  2552.                                                   (
  2553.                                                     name(E0022)
  2554.                                                     TITLE('E0022')
  2555.                                                     print
  2556.                                                     rules
  2557.                                                     (
  2558.                                                       S            (A B)
  2559.                                                       A            ( D(ignore))
  2560.                                                       B            ( D )
  2561.                                                       D(Z E(repeat))
  2562.                                                       Z('a')
  2563.                                                       E('z')
  2564.                                                     )
  2565.                                                     string(D);
  2566.                                                   )
  2567.  
  2568.  
  2569. ΓòÉΓòÉΓòÉ 6.22. Error N 0023 ΓòÉΓòÉΓòÉ
  2570.  
  2571. Error message format: 
  2572.                          L: 0023 'Secondary' in definition of nonterminal 
  2573.                          <<NTD>> in rule <<RD1>> conflicts with 'Not Secondary' 
  2574.                          in rule <<RD2>>. 
  2575.  
  2576. Error explanation: 
  2577.  
  2578. Error removal: 
  2579.                          Make decision and remove one of the markings. 
  2580.  
  2581. Error example: 
  2582.  
  2583.  
  2584. ΓòÉΓòÉΓòÉ 6.23. Error N 0024 ΓòÉΓòÉΓòÉ
  2585.  
  2586. Error message format: 
  2587.                          L: 0024 Unable to locate next state from state <<SD>> 
  2588.                          on <<RD>> in rule <<RD>>. 
  2589.  
  2590. Error explanation: 
  2591.                          It is internal error of LR. If you encountered this 
  2592.                          error then contact <<Transcedental Automation>> at ... 
  2593.  
  2594. Error removal: 
  2595.                          Contact <<Transcedental Automation>> 
  2596.  
  2597. Error example: 
  2598.  
  2599.  
  2600. ΓòÉΓòÉΓòÉ 6.24. Error N 0025 ΓòÉΓòÉΓòÉ
  2601.  
  2602. Error message format: 
  2603.                          L: 0025 Double exit from state <<SD>> on nonterminal 
  2604.                          <<NTD>>. 
  2605.  
  2606. Error explanation: 
  2607.                          * 
  2608.  
  2609. Error removal: 
  2610.                          * 
  2611.  
  2612. Error example: 
  2613.                          * 
  2614.  
  2615.  
  2616. ΓòÉΓòÉΓòÉ 6.25. Error N 0026 ΓòÉΓòÉΓòÉ
  2617.  
  2618. Error message format: 
  2619.                          L: 0026 Terminal symbol overlap on <<RD>> in rule 
  2620.                          <<RD>> which affects state <<SD>>. 
  2621.  
  2622. Error explanation: 
  2623.                          This is internal error of LR. Please contact 
  2624.                          <<Transcedental Automation>> if you encountered this 
  2625.                          error. 
  2626.  
  2627. Error removal: 
  2628.                          Please contact <<Transcedental Automation>> if you 
  2629.                          encountered this error. 
  2630.  
  2631. Error example: 
  2632.  
  2633.  
  2634. ΓòÉΓòÉΓòÉ 6.26. Error N 0027 ΓòÉΓòÉΓòÉ
  2635.  
  2636. Error message format: 
  2637.                          G: 0027 TITLE missing. 
  2638.  
  2639. Error explanation: 
  2640.                          A overall option 'title' is missed. 
  2641.  
  2642. Error removal: 
  2643.                          Insert the option title 
  2644.  
  2645. Error example: 
  2646.  
  2647.                                                   LR(
  2648.                                                      NAME(W0027)
  2649.                                                      RULES(
  2650.                                                           S('a')
  2651.                                                      )
  2652.                                                   )
  2653.  
  2654.  
  2655. ΓòÉΓòÉΓòÉ 6.27. Error N 0028 ΓòÉΓòÉΓòÉ
  2656.  
  2657. Error message format: 
  2658.                          L: 0028 Unused nonterminal <<NTD>>. 
  2659.  
  2660. Error explanation: 
  2661.                          <<NTD>> is defined but never used. 
  2662.  
  2663. Error removal: 
  2664.                          Check your grammar and remove <<NTD>> if it is not 
  2665.                          necessary for your grammar. 
  2666.  
  2667. Error example: 
  2668.                           Unused nonterminal 'A'. 
  2669.  
  2670.                                                   LR(
  2671.                                                      NAME(W0028)
  2672.                                                      Title('w0028')
  2673.                                                      RULES(
  2674.                                                           S('a')
  2675.                                                           A('b')
  2676.                                                      )
  2677.                                                   )
  2678.  
  2679.  
  2680. ΓòÉΓòÉΓòÉ 6.28. Error N 0029 ΓòÉΓòÉΓòÉ
  2681.  
  2682. Error message format: 
  2683.                          L: 0029 Undefined optional <<NTD>>. 
  2684.  
  2685. Error explanation: 
  2686.                          <<NTD>> used but not defined. 
  2687.  
  2688. Error removal: 
  2689.                          Define <<NTD>> in your grammar definition. 
  2690.  
  2691. Error example: 
  2692.  
  2693.                                                   LR(
  2694.                                                      NAME(W0029)
  2695.                                                      Title('w0029')
  2696.                                                      RULES(
  2697.                                                           S('a')
  2698.                                                      )
  2699.                                                      optional(A)
  2700.                                                   )
  2701.  
  2702.  
  2703. ΓòÉΓòÉΓòÉ 6.29. Error N 0030 ΓòÉΓòÉΓòÉ
  2704.  
  2705. Error message format: 
  2706.                          L: 0030 Undefined secondary <<NTD>>. 
  2707.  
  2708. Error explanation: 
  2709.                          <<NTD>> used but not defined. 
  2710.  
  2711. Error removal: 
  2712.                          Define <<NTD>> in your grammar definition 
  2713.  
  2714. Error example: 
  2715.  
  2716.                                                   LR(
  2717.                                                      NAME(W0030)
  2718.                                                      Title('w0030')
  2719.                                                      RULES(
  2720.                                                           S('a')
  2721.                                                      )
  2722.                                                      secondary(A)
  2723.                                                   )
  2724.  
  2725.  
  2726. ΓòÉΓòÉΓòÉ 6.30. Error N 0031 ΓòÉΓòÉΓòÉ
  2727.  
  2728. Error message format: 
  2729.                          L: 0031 Undefined string <<NTD>>. 
  2730.  
  2731. Error explanation: 
  2732.                          <<NTD>> used but not defined. 
  2733.  
  2734. Error removal: 
  2735.                          Define <<NTD>> in your grammar definition. 
  2736.  
  2737. Error example: 
  2738.  
  2739.                                                   LR(
  2740.                                                      NAME(W0031)
  2741.                                                      Title('w0031')
  2742.                                                      RULES(
  2743.                                                           S('a')
  2744.                                                      )
  2745.                                                      string(A)
  2746.                                                   )
  2747.  
  2748.  
  2749. ΓòÉΓòÉΓòÉ 6.31. Error N 0032 ΓòÉΓòÉΓòÉ
  2750.  
  2751. Error message format: 
  2752.                          L: 0032 Undefined zero <<NTD>>. 
  2753.  
  2754. Error explanation: 
  2755.                          <<NTD>> used but not defined. 
  2756.  
  2757. Error removal: 
  2758.                          Define <<NTD>> in your grammar definition. 
  2759.  
  2760. Error example: 
  2761.  
  2762.                                                   LR(
  2763.                                                      NAME(W0032)
  2764.                                                      Title('w0032')
  2765.                                                      RULES(
  2766.                                                           S('a')
  2767.                                                      )
  2768.                                                      zero(A)
  2769.                                                   )
  2770.  
  2771.  
  2772. ΓòÉΓòÉΓòÉ 6.32. Error N 0033 ΓòÉΓòÉΓòÉ
  2773.  
  2774. Error message format: 
  2775.                          L: 0033 Undefined repeat <<NTD>>. 
  2776.  
  2777. Error explanation: 
  2778.                          <<NTD>> used but not defined. 
  2779.  
  2780. Error removal: 
  2781.                          Define <<NTD>> in your grammar definition. 
  2782.  
  2783. Error example: 
  2784.  
  2785.                                                   LR(
  2786.                                                      NAME(W0033)
  2787.                                                      Title('w0033')
  2788.                                                      RULES(
  2789.                                                           S('a')
  2790.                                                      )
  2791.                                                      repeat(A)
  2792.                                                   )
  2793.  
  2794.  
  2795. ΓòÉΓòÉΓòÉ 6.33. Error N 0034 ΓòÉΓòÉΓòÉ
  2796.  
  2797. Error message format: 
  2798.                          L: 0034 Undefined choice <<NTD>>. 
  2799.  
  2800. Error explanation: 
  2801.                          <<NTD>> used but not defined. 
  2802.  
  2803. Error removal: 
  2804.                          Define <<NTD>> in your grammar definition. 
  2805.  
  2806. Error example: 
  2807.  
  2808.                                                   LR(
  2809.                                                      NAME(W0034)
  2810.                                                      Title('w0034')
  2811.                                                      RULES(
  2812.                                                           S('a')
  2813.                                                      )
  2814.                                                      choice(A)
  2815.                                                   )
  2816.  
  2817.  
  2818. ΓòÉΓòÉΓòÉ 6.34. Error N 0035 ΓòÉΓòÉΓòÉ
  2819.  
  2820. Error message format: 
  2821.                          L: 0035 Undefined ignore <<NTD>>. 
  2822.  
  2823. Error explanation: 
  2824.                          <<NTD>> used but not defined. 
  2825.  
  2826. Error removal: 
  2827.                          Define <<NTD>> in your grammar definition. 
  2828.  
  2829. Error example: 
  2830.  
  2831.                                                   LR(
  2832.                                                      NAME(W0035)
  2833.                                                      Title('w0035')
  2834.                                                      RULES(
  2835.                                                           S('a')
  2836.                                                      )
  2837.                                                      ignore(A)
  2838.                                                   )
  2839.  
  2840.  
  2841. ΓòÉΓòÉΓòÉ 6.35. Error N 0036 ΓòÉΓòÉΓòÉ
  2842.  
  2843. Error message format: 
  2844.                          L: 0036 Duplicate rule name <<RD>> within nonterminal 
  2845.                          <<NTD>>. 
  2846.  
  2847. Error explanation: 
  2848.                          * 
  2849.  
  2850. Error removal: 
  2851.                          * 
  2852.  
  2853. Error example: 
  2854.                          * 
  2855.  
  2856.  
  2857. ΓòÉΓòÉΓòÉ 6.36. Error N 0037 ΓòÉΓòÉΓòÉ
  2858.  
  2859. Error message format: 
  2860.                          L: 0037 Reduce-shift conflict from state <<SD>>, shift 
  2861.                          text <<STRD>> or reduce by <<RD>>. 
  2862.  
  2863. Error explanation: 
  2864.                          * 
  2865.  
  2866. Error removal: 
  2867.                          * 
  2868.  
  2869. Error example: 
  2870.  
  2871.  
  2872. ΓòÉΓòÉΓòÉ 7. Source text parsing ΓòÉΓòÉΓòÉ
  2873.  
  2874. To use LR from an application program, you can: 
  2875.  
  2876. o either use lrx_req - the "do everything" procedure , located in LRX.C. 
  2877.  
  2878. o or use the parsing primitives directly. 
  2879.  
  2880. In either case, the steps to perform a parse are the same. 
  2881.  
  2882.  
  2883. ΓòÉΓòÉΓòÉ 8. Syntax-directed semantic processing of parse tree ΓòÉΓòÉΓòÉ
  2884.  
  2885. A result of successful source text parsing is a parse tree. According to LR the 
  2886. further processing of the parse tree is made within syntax-directed semantic 
  2887. processing scheme. This scheme is useful because it allows the designer to 
  2888. express the semantic processing directly in terms of the syntactic structure of 
  2889. the source language. A syntax-directed processing scheme is merely a 
  2890. context-free grammar in which a procedure called a semantic action is 
  2891. associated with each production. Consider for instance semantic action b is 
  2892. associated with production B ( C D E )  The semantic action b is executed 
  2893. whenever the traversal of parse tree reach a tree-node corresponding to 
  2894. nonterminal B . 
  2895.  
  2896. The semantic action may involve the computation of values for variables 
  2897. belonging to the user program (to the compiler for example), the printing of an 
  2898. error diagnostic, or the placement of some value in a data structure. The 
  2899. values computed by action b quite frequently are associated with the parse tree 
  2900. nodes corresponding to the instance of nonterminal B . 
  2901.  
  2902. About semantic actions and parse tree elements linkage see lrx_parse (parse 
  2903. text with semantic actions). 
  2904.  
  2905. To navigate parse tree there are several program primitives and data 
  2906. structures: 
  2907.  
  2908. o C-data structures for parse tree; 
  2909.  
  2910. o Parse tree navigation primitives. 
  2911.  
  2912. Example of program performing a parse tree navigation. 
  2913.  
  2914.  
  2915. ΓòÉΓòÉΓòÉ 8.1. C-data structures for parse tree ΓòÉΓòÉΓòÉ
  2916.  
  2917.  To navigate parse tree there are several data structures: 
  2918.  
  2919. o LR_P - result parse tree; 
  2920. o LR_PT -  parse tree element; 
  2921. o XL, Xl -  arrival order list; 
  2922. o LRX_PT -  nonterminal pointer set. 
  2923.  
  2924.  
  2925. ΓòÉΓòÉΓòÉ 8.1.1. LR_P    Result parse tree ΓòÉΓòÉΓòÉ
  2926.  
  2927. Description:
  2928.  
  2929.         Parse results
  2930.  
  2931. Fields:
  2932.  
  2933.         LR2    *lr;           - pointer parsing table
  2934.         LR_PT  *parse_tree;   - pointer arse tree
  2935.         char   *text;         - pointer text to be parsed
  2936.         char   *path;         - pointer path to be used for file names
  2937.         char   *parse;        - pointer file on which parse were printed
  2938.         char   *error;        - pointer file on which errors were printed
  2939.         long    pts;          - Number of parse tree elements
  2940.         long    errors;       - Error count
  2941.         char   *error_text;   - pointer position in text at which error was detected
  2942.         XT      EXPECTED;     - Expected nonterminals at error
  2943.         char   *next;         - pointer next characters
  2944.  
  2945.  
  2946. ΓòÉΓòÉΓòÉ 8.1.2. LR_PT   Parse tree element ΓòÉΓòÉΓòÉ
  2947.  
  2948. Description:
  2949.  
  2950.         Parse tree element.
  2951.  
  2952. Fields:
  2953.  
  2954.         char   *t;            - pointer to source text (ASCIIZ).
  2955.                                 If current nonterminal was not reduced from
  2956.                                 terminal, it is NULL.
  2957.  
  2958.         long    chars,lines;  - Amount of spacing between items
  2959.                                 in parse tree.
  2960.  
  2961.         char   *k;            - pointer to name of current nonterminal.
  2962.  
  2963.         Xl      Pl;           - Arrival order.
  2964.  
  2965.         XL      PL;           - Arrival order list.
  2966.  
  2967.  
  2968. ΓòÉΓòÉΓòÉ 8.1.3. XL+Xl   Arrival order list ΓòÉΓòÉΓòÉ
  2969.  
  2970. Description:
  2971.  
  2972. Arrival order list
  2973.  
  2974. Type:
  2975.  
  2976. XL      - List of pointers to void.
  2977.  
  2978. Fields:
  2979.  
  2980. f       - pointer to the first element.
  2981. l       - pointer to the last element.
  2982. d       - pointer to the data associated with list.
  2983.  
  2984.  
  2985.  
  2986. Type:
  2987.  
  2988. Xl      - element of XL.
  2989.  
  2990. Fields:
  2991.  
  2992. n       - pointer to the next element
  2993. p       - pointer to the previous element
  2994. u       - pointer to the list(XL) that own this element.
  2995. d       - pointer to data associated with this list element.
  2996.  
  2997. Usage in LR_PT: 
  2998.  
  2999. When this structures are used in in LR_PT field 'd' of both of them points to 
  3000. the begin of LR_PT structure than own those structures. 
  3001.  
  3002. For example: 
  3003.  
  3004. LR_PT *a,*b;
  3005.  
  3006. b = a->PL->f->d;// b - pointer to the first son of 'a'.
  3007. a = b->Pl->u->d;// a - pointer to the parent of 'b'
  3008.  
  3009.  
  3010. ΓòÉΓòÉΓòÉ 8.1.4. LRX_PT  Nonterminal pointer set ΓòÉΓòÉΓòÉ
  3011.  
  3012. Nonterminal pointer set 
  3013.  
  3014. Description:
  3015.  
  3016.         Nonterminal pointer set.
  3017.  
  3018. Fields:
  3019.  
  3020.         LR_PT *l;             - Pointer to currently selected nonterminal
  3021.  
  3022.         LR_P  *p;             - Pointer to parse results
  3023.  
  3024.         LR_PT *key[];         - Array of pointers to nonterminals
  3025.  
  3026.  
  3027. ΓòÉΓòÉΓòÉ 8.2. Parse tree navigation primitives ΓòÉΓòÉΓòÉ
  3028.  
  3029.  To navigate parse tree there are several program primitives : Parse tree 
  3030. navigation primitives. 
  3031.  
  3032.  
  3033. ΓòÉΓòÉΓòÉ 8.2.1. lrx_parse - parse text with semantic actions ΓòÉΓòÉΓòÉ
  3034.  
  3035.  SYNTAX: 
  3036.                      void  lrx_parse(LR_P **p,void (**cmd)(), void 
  3037.                     (**cmd2)(),LRX_PT *PT,LR2 *grammar,char *text,long 
  3038.                     stack,void *sysp); 
  3039.  
  3040.  PARAMETERS: 
  3041.  
  3042.     LR_P **p  if p != 0 after calling then *p is pointer to parse result else 
  3043.              function release memory allocated by a parser 
  3044.  
  3045.     void (**cmd)()  vector of semantic action for prefix traversal. 
  3046.              The function with index i from this ( cmd ) and next ( cmd2 ) 
  3047.              vectors will be  called just as 'cmd[i](void *sysp,LRX_PT* 
  3048.              PT,LR_PT pt)', where 'sysp' and 'PT' are parameters of the 
  3049.              lrx_parse-call and 'pt' is a current parse tree node. 
  3050.  
  3051.     void (**cmd2)()  vector of semantic action for postfix traversal. See  void 
  3052.              (**cmd)() . 
  3053.  
  3054.     LRX_PT *PT  pointer to a nonterminal pointer set. 
  3055.  
  3056.     LR2 *grammar  the compiled grammar. 
  3057.  
  3058.     char *text  text that will be parsed. 
  3059.  
  3060.     long stack  size of stack of automaton. 
  3061.  
  3062.     void *sysp  parameter passed to cmd[i]. 
  3063.  
  3064.  EFFECT: 
  3065.                      Parse text using grammar grammar with stack size stack. If 
  3066.                     cmd  !=0  do a prefix traversal of parse tree using it. If 
  3067.                     cmd2 !=0  do a postfix traversal of parse tree using it. If 
  3068.                     p   != 0 ,set *p points to parse result else release memory 
  3069.                     allocated by parse. 
  3070.  
  3071.  RETURN: 
  3072.                      Nothing. 
  3073.  
  3074.  
  3075. ΓòÉΓòÉΓòÉ 8.2.2. lrx_n - Returns number of nonterminal  ΓòÉΓòÉΓòÉ
  3076.  
  3077.  SYNTAX: 
  3078.              lrx_n ( LR_PT *_PT ) 
  3079.  
  3080.  PARAMETERS: 
  3081.  
  3082.     _PT      pointer to nonterminal (parse tree node) 
  3083.  
  3084.  EFFECT: 
  3085.              None 
  3086.  
  3087.  RETURN: 
  3088.              number of nonterminal *_PT. 
  3089.  
  3090.  
  3091. ΓòÉΓòÉΓòÉ 8.2.3. lrx_loc - Places nonterminal into NPS  ΓòÉΓòÉΓòÉ
  3092.  
  3093.  SYNTAX: 
  3094.              lrx_loc ( <<NAME >>_PT _KEYS, LR_PT *_PT ) 
  3095.  
  3096.  PARAMETERS: 
  3097.  
  3098.     _KEYS    nonterminal pointer set 
  3099.  
  3100.     _PT      pointer to nonterminal 
  3101.  
  3102.  EFFECT: 
  3103.              places _PT to nonterminal pointer set _KEYS using number of *_PT 
  3104.  
  3105.  RETURN: 
  3106.              None. 
  3107.  
  3108.  
  3109. ΓòÉΓòÉΓòÉ 8.2.4. lrx_one - Returns pointer to singleton son of nonterminal  ΓòÉΓòÉΓòÉ
  3110.  
  3111.  SYNTAX: 
  3112.              lrx_one ( LR_PT *_PT ) 
  3113.  
  3114.  PARAMETERS: 
  3115.  
  3116.     _PT      pointer to nonterminal 
  3117.  
  3118.  EFFECT: 
  3119.              None 
  3120.  
  3121.  RETURN: 
  3122.              pointer to son of *_PT if *_PT has only one son or zero otherwise. 
  3123.  
  3124.  
  3125. ΓòÉΓòÉΓòÉ 8.2.5. lrx_zero - Initializes NPS with information from parse results  ΓòÉΓòÉΓòÉ
  3126.  
  3127.  SYNTAX: 
  3128.              lrx_zero ( <<NAME >>_PT _KEYS, LR_P *_P ) 
  3129.  
  3130.  PARAMETERS: 
  3131.  
  3132.     _KEYS    nonterminal pointer set 
  3133.  
  3134.     _P       pointer to parse results 
  3135.  
  3136.  EFFECT: 
  3137.              initializes _KEYS using information from *_P and bounds _KEYS with 
  3138.             *_P 
  3139.  
  3140.  RETURN: 
  3141.              None. 
  3142.  
  3143.  
  3144. ΓòÉΓòÉΓòÉ 8.2.6. lrx_add - Places nonterminal and singleton sons of this nonterminal into NPS  ΓòÉΓòÉΓòÉ
  3145.  
  3146.  SYNTAX: 
  3147.              lrx_add ( <<NAME >>_PT _KEYS, LR_PT *_PT ) 
  3148.  
  3149.  PARAMETERS: 
  3150.  
  3151.     _KEYS    nonterminal pointer set 
  3152.  
  3153.     _PT      pointer to nonterminal 
  3154.  
  3155.  EFFECT: 
  3156.              places _PT and all singleton sons of *_PT into _KEYS 
  3157.  
  3158.  RETURN: 
  3159.              None. 
  3160.  
  3161.  
  3162. ΓòÉΓòÉΓòÉ 8.2.7. lrx_all - Places given nonterminal and all sons of this nonterminal  ΓòÉΓòÉΓòÉ
  3163.  
  3164.  SYNTAX: 
  3165.              lrx_all ( <<NAME >>_PT _KEYS, LR_PT *_PT ) 
  3166.  
  3167.  PARAMETERS: 
  3168.  
  3169.     _KEYS    nonterminal pointer set 
  3170.  
  3171.     _PT      pointer to nonterminal 
  3172.  
  3173.  EFFECT: 
  3174.              places _PT and pointers to all sons of *_PT (until leaves) to 
  3175.             _KEYS 
  3176.  
  3177.  RETURN: 
  3178.              None. 
  3179.  
  3180.  
  3181. ΓòÉΓòÉΓòÉ 8.2.8. lrx_zap - Initializes NPS with parse results and places all sons of given nonterminal and the nonterminal itself into NPS  ΓòÉΓòÉΓòÉ
  3182.  
  3183.  SYNTAX: 
  3184.              lrx_zap ( <<NAME >>_PT _KEYS, LR_P *_P, LR_PT *_PT ) 
  3185.  
  3186.  PARAMETERS: 
  3187.  
  3188.     _KEYS    nonterminal pointer set 
  3189.  
  3190.     _P       pointer to parse results 
  3191.  
  3192.     _PT      pointer to nonterminal 
  3193.  
  3194.  EFFECT: 
  3195.              initializes _KEYS with *_P (using lrx_zero()) and places _PT and 
  3196.             pointers to all sons of *_PT (until leaves) into _KEYS 
  3197.  
  3198.  RETURN: 
  3199.              None. 
  3200.  
  3201.  
  3202. ΓòÉΓòÉΓòÉ 8.2.9. lrx_up - Scans parse tree up  ΓòÉΓòÉΓòÉ
  3203.  
  3204.  SYNTAX: 
  3205.              lrx_up ( <<NAME >>_PT _KEYS, LR_PT *_PT, expression _UNTIL ) 
  3206.  
  3207.  PARAMETERS: 
  3208.  
  3209.     _KEYS    nonterminal pointer set 
  3210.  
  3211.     _P       pointer to parse results 
  3212.  
  3213.     _UNTIL   expression (e.g. a+b%s<d->fr-87) 
  3214.  
  3215.  EFFECT: 
  3216.              looks up through parse tree from *_PT until top of the tree 
  3217.             encountered or expression _UNTIL becomes non zero, placing all 
  3218.             encountered nonterminals (including last) into _KEYS. 
  3219.  
  3220.  RETURN: 
  3221.              None. 
  3222.  
  3223.  
  3224. ΓòÉΓòÉΓòÉ 8.2.10. lrx_copy - Copies one NPS to another NPS  ΓòÉΓòÉΓòÉ
  3225.  
  3226.  SYNTAX: 
  3227.              lrx_copy ( <<NAME >>_PT _KEYS, <<NAME >>_PT _FROM ) 
  3228.  
  3229.  PARAMETERS: 
  3230.  
  3231.     _KEYS    nonterminal pointer set 
  3232.  
  3233.     _FROM    nonterminal pointer set 
  3234.  
  3235.  EFFECT: 
  3236.              copies _FROM to _KEYS 
  3237.  
  3238.  RETURN: 
  3239.              None. 
  3240.  
  3241.  
  3242. ΓòÉΓòÉΓòÉ 8.2.11. lrx_list_do - Scans list associated with given nonterminal and passes control to user-routine on every iteration  ΓòÉΓòÉΓòÉ
  3243.  
  3244.  SYNTAX: 
  3245.              lrx_list_do ( LR_PT *_PT, Xl *_L, void *_pt) 
  3246.  
  3247.  PARAMETERS: 
  3248.  
  3249.     _PT      head of list 
  3250.  
  3251.     _L       pointer to current list element 
  3252.  
  3253.     _pt      pointer to data associated with current list element 
  3254.  
  3255.  EFFECT: 
  3256.              scans all given nonterminal as list from begin to end of *_PT and 
  3257.             on every iteration places pointer to current list element into _L 
  3258.             and pointer to data field of current element into _pt. Used as 
  3259.             header for cycle (e.g. 
  3260.             lrx_list_do(Pnt,PCurElem,PCurData){process(PCurData); 
  3261.             clear(PCurElem);} ) 
  3262.  
  3263.  RETURN: 
  3264.              None. 
  3265.  
  3266.  
  3267. ΓòÉΓòÉΓòÉ 8.2.12. lrx_tree_do - Scans tree associated with given nonterminal and passes control to user-routine on every iteration  ΓòÉΓòÉΓòÉ
  3268.  
  3269.  SYNTAX: 
  3270.              lrx_tree_do ( LR_PT *_PT, Xt *_T, void *_pt) 
  3271.  
  3272.  PARAMETERS: 
  3273.  
  3274.     _PT      head of tree 
  3275.  
  3276.     _T       pointer to current tree element 
  3277.  
  3278.     _pt      pointer to data associated with current tree element 
  3279.  
  3280.  EFFECT: 
  3281.              scans all given nonterminal as tree up-down and left-right to the 
  3282.             end of *_PT and on every iteration places pointer to current tree 
  3283.             element into _T and pointer to data field of current element into 
  3284.             _pt. Used as header for cycle (e.g. 
  3285.             lrx_tree_do(Pnt,PCurElem,PCurData){process(PCurData); 
  3286.             clear(PCurElem);}) 
  3287.  
  3288.  RETURN: 
  3289.              None. 
  3290.  
  3291.  
  3292. ΓòÉΓòÉΓòÉ 9. LRX_REQ - the "do everything" procedure. ΓòÉΓòÉΓòÉ
  3293.  
  3294. This section describes how to use lrx_req to accomplish a variety of parsing 
  3295. tasks.  It uses the sample program LR_SQL.C to format a request to lrx_req  via 
  3296. the LRX_REQ structure. 
  3297.  
  3298. It will probably be easiest to explain how to use lrx_req if you perform the 
  3299. following actions in WorkFrame/2 as you read this part of this guide. 
  3300.  
  3301. Copy the LR_SQL.PRJ file from the source diskette into \IBMWF to create the 
  3302. LR_SQL example project.  It assumes that your working directory is C:\LR. 
  3303. Change the project description and make-file if this not the case. 
  3304.  
  3305. If you have not already compiled the SQL grammar, do so now by running the make 
  3306. file for this project.  There will be a delay of 30 plus seconds while the 
  3307. grammar is compiled.  Compilation will produce the following files: 
  3308.  
  3309. LR_SQL.STR This file contains preprocessor constants, macros, and C structure 
  3310.           declarations which help you work with the parse tree. 
  3311.  
  3312. LR_SQL.CC  This file contains generated C code to help you get addressability 
  3313.           from one nonterminal to its immediate descendents. 
  3314.  
  3315. LR_SQL.N  An abbrieviated version of LR_SQL.STR 
  3316.  
  3317. Examine program LR_SQL.C. 
  3318.  
  3319. Line 1    Should be included all programs, it defines constants and data 
  3320.           structures need to perform a parse. 
  3321.  
  3322.           Lines 2-3 are the files generated from the SQL grammar. 
  3323.  
  3324.           Lines 4-5 are the definitions of semantic routines.  The lrx_cmd 
  3325.           macro simplifies their declaration. 
  3326.  
  3327. Line 7    Declares an instance r of the parsing request structure LRX_REQ.  The 
  3328.           following paragraphs describe how to set up this structure so that 
  3329.           lrx_req will perform the desired processing.  This structure is 
  3330.           completely described in:  the LRX_REQ structure. 
  3331.  
  3332. Line 8    Declares cmd. it consists of two arrays of function pointers, pre and 
  3333.           post, for each nonterminal in the grammar. The LR_SQL_STR file 
  3334.           contains preprocessor constants <<GRAMMAR>>_<<NON_TERMINAL>>_n, e.g. 
  3335.           LR_SQL_SELECT_n, which give the number of each nonterminal in this 
  3336.           grammar.  The addresses of the semantic functions for each 
  3337.           nonterminal are placed in the cmd.pre, and cmd.post arrays indexed by 
  3338.           these numbers, as shown on lines 13-15. Entries which are not in use 
  3339.           should be set to 0, or a default procedure. 
  3340.  
  3341.           r.pre and r.post should address the appropriate function arrays as 
  3342.           shown on lines 11, 12.  If an array is not being used, the r.pre, or 
  3343.           r.post (or both) pointers should be 0. 
  3344.  
  3345.           The semantic functions are called as LR traverses the persistent 
  3346.           parse tree built internally during the syntax phase.  pre functions 
  3347.           are called before the pre  functions for a non terminal's descendents 
  3348.           in the parse tree.  post  routines are called after the post 
  3349.           routines for a nonterminal's descendents have been processed.  So for 
  3350.           a typical fragment of a parse tree: 
  3351.  
  3352.  
  3353.                             A
  3354.                        +----+----+
  3355.                        B    C    F
  3356.                             +
  3357.                          +--+--+
  3358.                          D     E
  3359.  
  3360.           The calling sequence will be: 
  3361.  
  3362.     1. PRE  A 
  3363.     2. PRE  B 
  3364.     3. POST B 
  3365.     4. PRE  C 
  3366.     5. PRE  D 
  3367.     6. POST D 
  3368.     7. PRE  E 
  3369.     8. POST E 
  3370.     9. POST C 
  3371.    10. PRE  F 
  3372.    11. POST F 
  3373.    12. POST A 
  3374.  
  3375. Line 9    LR_SQL_NPS is the generated Nonterminal Pointer Set (NPS) work area. 
  3376.           You need at least one to process a parse. Addressability to it should 
  3377.           be set in r.nps, as shown on line 13. An NPS is used by the parsing 
  3378.           primitives to get addressability to a related nonterminals in the 
  3379.           parse tree. 
  3380.  
  3381. Line 14, 15 Sets the pre command area to the default print routine.  Line 16 
  3382.           sets in a specific routine to handle the CREATE_TS_OPTIONS 
  3383.           nonterminal. 
  3384.  
  3385. Lines 17-23 Complete the set up of r. 
  3386.  
  3387.    Line 17.  Specifies the file containing the input text.  You may parse 
  3388.              either a file, or a string.  Line 20 sets the bit indicating that 
  3389.              the contents of the file are to be read during the parse. 
  3390.  
  3391.    Line 18.  Specifies the .LRS file containing the compiled grammar.  You can 
  3392.              of course compile the grammar from lrx_req.  In this case we are 
  3393.              assuming that the grammar has already been prepared by running 
  3394.              LR_SQL.MAK, as descibed at the top of this section. 
  3395.  
  3396.    Lines 19-23. Specifies the processing actions required. In this case, the 
  3397.              grammar is to be loaded from the specified file, as is the text to 
  3398.              be parsed.  A parse is required, during which the semantic 
  3399.              functions will be invoked. After parsing the parse tree will be 
  3400.              printed, by default to LR_SQL.PRS. Finally all resources will be 
  3401.              freed.  You may retain resources to avoid having to reload them 
  3402.              for the next action. 
  3403.  
  3404. Line 24.  The call to lrx_req is on line 24.  lrx_req carries out the required 
  3405.           actions.  If errors are found, r.rc is set to a non zero value, 
  3406.           otherwise, the semantic action functions will be invoked. 
  3407.  
  3408.           In this program the semantic functions are: 
  3409.  
  3410.    Lines 27 to 29. Print the details of a nonterminal. 
  3411.  
  3412.    Lines 33 to 41. Process some of the create options for a tablespace. 
  3413.  
  3414.           Each semantic function has a standard parameter list: 
  3415.  
  3416.    REQ       The request structure to lrx_req 
  3417.  
  3418.    PT        Pointer to the current nonterminal 
  3419.  
  3420. Lines 34,35 Demonstrates one way of obtaining access to the non terminals 
  3421.           beneath the current nonterminal.  Each nonterminal has an associated, 
  3422.           generated structure declared in lr_sql.str, which names the 
  3423.           nonterminals that can appear beneath it.  LR_SQL.CC contains 
  3424.           generated routines to load this structure from the current 
  3425.           nonterminal. 
  3426.  
  3427.           Line 34 shows how to declare such a structure, while line 35 shows 
  3428.           how to call the associated routine for locating the descendent non 
  3429.           terminals. 
  3430.  
  3431. Try running the program under the C debugger.  Set break points at //26 and 
  3432. //35 to watch the processing of each nonterminal. 
  3433.  
  3434.  
  3435. ΓòÉΓòÉΓòÉ 9.1. The LRX_REQ structure ΓòÉΓòÉΓòÉ
  3436.  
  3437. The LRX_REQ structure define in LRX.INC is used to request services from 
  3438. procedure 'lrx_req', the "do everything" procedure. The LRX_REQ structure 
  3439. contains the following fields: 
  3440.  
  3441. long   req Actions to be performed as per lrx_req_* constants - see below. You 
  3442.           must specify some action in this field.  All subsequent fields are 
  3443.           either optional input fields to support the requested actions, or 
  3444.           output fields. 
  3445.  
  3446.           The following constants can be | together to request actions.  They 
  3447.           are listed in the order that lrx_req performs them. 
  3448.  
  3449.    lrx_req_load_gdl Load GDL file.  The loaded text will be addressed via gdl. 
  3450.              You will need to specify lrx_req_free_gdl on this or a future 
  3451.              action to free this memory.  GDL must be loaded for a grammar to 
  3452.              be compiled. 
  3453.  
  3454.    lrx_req_compile_gdl Compile GDL to create grammar file.  Assumes that gdl 
  3455.              points to the grammar text to be compiled.  A successful compile 
  3456.              will result in the grammar_file being set to the file that 
  3457.              contains the compiled grammar, for subsequent use in a load 
  3458.              grammar request. 
  3459.  
  3460.    lrx_req_load_grammar Load grammar file.  A grammar must be loaded before it 
  3461.              can be used to parse a string.  You may have multiple grammars 
  3462.              loaded at the same time. 
  3463.  
  3464.    lrx_req_load_text Load text file.  Reads the file whose name is pointed to 
  3465.              by text_file, and sets text to point to the loaded string. 
  3466.              Alternatively, you may supply your own string to be parsed, it may 
  3467.              contain new line characters and other whitespace.  It should be 0 
  3468.              terminated. 
  3469.  
  3470.    lrx_req_strip_comments Remove *, -- comment lines from input text.  It is 
  3471.              necessary to remove positional comments (i.e. a comment that is 
  3472.              independent of the syntactic position), before parsing. 
  3473.  
  3474.    lrx_req_parse Perform parse, invoking the pre and post procedures.  A Non 
  3475.              terminal Pointer Set work area is also required.  See  how to use 
  3476.              lrx_req  for an example of setting up pre and post commands, and 
  3477.              how to set up the NPS area. 
  3478.  
  3479.    lrx_req_print_parse Print parse tree to <<GRAMMAR>>.PRS.  Assists in code 
  3480.              development by showing you an actual parse tree. 
  3481.  
  3482.    lrx_req_rescan Rescan the parse tree invoking the semantic routines. 
  3483.  
  3484.    lrx_req_free_parse Free parse tree, otherwise it is kept in memory. 
  3485.  
  3486.    lrx_req_free_grammar Free grammar loaded version of compoiled grammar, 
  3487.              otherwise it it is kept in memory. 
  3488.  
  3489.    lrx_req_free_gdl Free GDL source statements, otherwise the source of the 
  3490.              grammar is kept in memory. 
  3491.  
  3492.    lrx_req_free_text Free the text to be parsed, otherwise it is kept in 
  3493.              memory. 
  3494.  
  3495.    lrx_req_free_compile Free compilation results, otherwise they are kept in 
  3496.              memory. 
  3497.  
  3498.    lrx_req_free_all Equivalent to: 
  3499.  
  3500.                           lrx_req_free_parse    |
  3501.                           lrx_req_free_grammar  |
  3502.                           lrx_req_free_gdl      |
  3503.                           lrx_req_free_text     |
  3504.                           lrx_req_free_compile
  3505.  
  3506. long   rc Output return code as defined in lrx_req_rc_* constants. 
  3507.  
  3508.           The following constants are | together into the rc field to provide a 
  3509.           return code from lrx_req. 
  3510.  
  3511.    lrx_req_rc_ok         0 - Request performed successfully 
  3512.  
  3513.    lrx_req_rc_no_grammar     No grammar supplied but parse requested 
  3514.  
  3515.    lrx_req_rc_no_grammar_file   No grammar file supplied, but load grammar 
  3516.              requested 
  3517.  
  3518.    lrx_req_rc_bad_grammar_file  Bad grammar file supplied - errors occurred 
  3519.              during read 
  3520.  
  3521.    lrx_req_rc_no_gdl       No GDL text supplied, but compile grammar requested 
  3522.  
  3523.    lrx_req_rc_no_gdl_file     No GDL file supplied, but load GDL file requested 
  3524.  
  3525.    lrx_req_rc_bad_gdl_file    Bad GDL file, errors occurred during read 
  3526.  
  3527.    lrx_req_rc_no_text       No input text to be parsed, but parse, or comment 
  3528.              strip requested 
  3529.  
  3530.    lrx_req_rc_no_text_file    No input text file to be loaded, but load text 
  3531.              file requested 
  3532.  
  3533.    lrx_req_rc_bad_text_file    Bad input text file, errors occurred during read 
  3534.  
  3535.    lrx_req_rc_compile_errors   Compile errors occurred, check <<GRAMMAR>>.LR 
  3536.  
  3537.    lrx_req_rc_parse_errors    Parse errors occurred,  check <<GRAMMAR>>.ERR 
  3538.  
  3539.    lrx_req_rc_no_nps       No Nonterminal Pointer Set work area supplied 
  3540.  
  3541.    lrx_req_rc_no_action      No action specified 
  3542.  
  3543.    lrx_req_rc_no_name       No grammar name supplied, but gramar compile 
  3544.              requested 
  3545.  
  3546.    lrx_req_rc_no_parse_to_free  No parse to free per request 
  3547.  
  3548.    lrx_req_rc_no_text_to_free   No text to free per request 
  3549.  
  3550.    lrx_req_rc_no_grammar_to_free No compiled grammar to free per request 
  3551.  
  3552.    lrx_req_rc_no_gdl_to_free   No GDL to free per request 
  3553.  
  3554.    lrx_req_rc_no_compile_to_free No compilation results to free per request 
  3555.  
  3556.    lrx_req_rc_no_parse_tree    No parse tree available for printing 
  3557.  
  3558. char  *name Input name of grammar - only required if you are compiling a 
  3559.           grammar 
  3560.  
  3561. LR_P  *P  Output parse tree.  Set by a successful parse 
  3562.  
  3563. LR   *lr  Output GDL grammar compilation results.  Set as a result of grammar 
  3564.           compilation 
  3565.  
  3566. LR2   *grammar Output - Set as a result of a successful grammar load grammar 
  3567.  
  3568. char  *grammar_file Input - File containing compiled grammar to be used for 
  3569.           this parse. If you have compiled one or more grammars with this 
  3570.           request structure, the name of the file containing the last 
  3571.           successfully compiled grammar is automaticallly placed in this field. 
  3572.  
  3573. char  *gdl Input/Output.  String containing source GDL for grammar.  Set by GDL 
  3574.           load from file request, or you may set it yourself to the string 
  3575.           containing the grammar to be compiled. 
  3576.  
  3577. char  *gdl_file Input - File containing source GDL for grammar.  Set this field 
  3578.           if you intend to compile a GDL file. 
  3579.  
  3580. char  *text Input/Output - Text to be parsed.  Set by load text from file 
  3581.           request, or you may set it yourself. 
  3582.  
  3583. char  *text_file Input - File containing text to be parsed.  Set this field if 
  3584.           you intend to request that the text to be parsed be read from a file. 
  3585.  
  3586. void (**pre)() Input - Pointer to Pre commands. An array of function pointers, 
  3587.           one per nonterminal in the grammar.  The number of each nonterminal 
  3588.           is declared for you as a preprocessor constant in <<GRAMMAR>>.str. 
  3589.           See using lrx_req 
  3590.  
  3591. void (**post)() Input - Pointer to Post commands. An array of function 
  3592.           pointers, one per nonterminal in the grammar.  The number of each 
  3593.           nonterminal is declared for you as a preprocessor constant in 
  3594.           <<GRAMMAR>>.str.  See using lrx_req 
  3595.  
  3596. void  *nps Pointer to Nonterminal Pointer Set.  A work area of size (void *) * 
  3597.           number of nonterminals in the grammar. 
  3598.  
  3599. long   stack Default parser stack, will be set to 4K unless you set it higher. 
  3600.           4K has always proven satisfactory. 
  3601.  
  3602. void  *sysp User parameter.  You may use this pointer to chain additional user 
  3603.           data.  The LRX_REQ structure is passed as a parameter to each pre and 
  3604.           post command invoked. 
  3605.  
  3606.  
  3607. ΓòÉΓòÉΓòÉ 10. Direct usage of parsing primitives ΓòÉΓòÉΓòÉ
  3608.  
  3609. How to use LR from your application program directly ? 
  3610.  
  3611.  1. If you already have LR-parsing table go to step 4. 
  3612.  
  3613.  2. Compile grammar ( lr_open ). 
  3614.  
  3615.  3. Release memory allocated by it ( lr_free ). 
  3616.  
  3617.  4. Load LR-parsing table ( lr2_open ). 
  3618.  
  3619.  5. Parse input files ( lr_parse_open ). 
  3620.  
  3621.  6. Use results with lrx-functions (Parse tree navigation primitives). 
  3622.  
  3623.  7. Free memory used by this parse ( lr_parse_free ). 
  3624.  
  3625.  8. If you need parse another text go to step 5. 
  3626.  
  3627.  9. Free resources allocated by compiled grammar ( lr2_free ). 
  3628.  
  3629.  
  3630. ΓòÉΓòÉΓòÉ 10.1. Usage of the LR-parser within WorkFrame/2 ΓòÉΓòÉΓòÉ
  3631.  
  3632. Usage of the LR-parser within WorkFrame/2 is like usage of the LR-parser within 
  3633. WorkFrame/2 . 
  3634.  
  3635.  
  3636. ΓòÉΓòÉΓòÉ 10.2. Input data for the LR parser ΓòÉΓòÉΓòÉ
  3637.  
  3638. Input data for the LR parser is the text file containing the grammar 
  3639. definition. The grammar definition must be given on  GDL 
  3640.  
  3641.  
  3642. ΓòÉΓòÉΓòÉ 10.3. Call of LR parser by user program ΓòÉΓòÉΓòÉ
  3643.  
  3644. For call of LR parser by user program the following C-functions are presented: 
  3645.  
  3646. lr2_open - open compiled grammar; 
  3647.  
  3648. lr2_free - release resources allocated by compiled grammar; 
  3649.  
  3650. lr_parse_open - perform a parse; 
  3651.  
  3652. lr_print_parse - print parse results; 
  3653.  
  3654. lr_parse_free -  Release the results of a parse. 
  3655.  
  3656. See also Example of program performing a parse tree navigation. 
  3657.  
  3658.  
  3659. ΓòÉΓòÉΓòÉ 10.3.1. lr2_open - open compiled grammar  ΓòÉΓòÉΓòÉ
  3660.  
  3661.  SYNTAX: 
  3662.                      int   lr2_open       (LR2 **lr, char *ds); 
  3663.  
  3664.  PARAMETERS: 
  3665.  
  3666.     LR2 **lr  pointer to pointer to compiled grammar that will be loaded by 
  3667.              this function. 
  3668.  
  3669.     char* ds  Name of file contained compiled grammar. 
  3670.  
  3671.  EFFECT: 
  3672.                      Load compiled grammar to memory from file named 'ds' and 
  3673.                     place pointer to  it in '*lr'. 
  3674.  
  3675.  RETURN: 
  3676.                      Nothing. 
  3677.  
  3678.  
  3679. ΓòÉΓòÉΓòÉ 10.3.2. lr2_free - release resources allocated by compiled grammar.  ΓòÉΓòÉΓòÉ
  3680.  
  3681.  SYNTAX: 
  3682.                      void  lr2_free       (LR2  *lr); 
  3683.  
  3684.  PARAMETERS: 
  3685.  
  3686.     LR2 *lr  pointer to loaded compiled grammar. 
  3687.  
  3688.  EFFECT: 
  3689.                      release resources allocated by lr2_open. 
  3690.  
  3691.  RETURN: 
  3692.                      Nothing. 
  3693.  
  3694.  
  3695. ΓòÉΓòÉΓòÉ 10.3.3. lr_parse_open - perform a parse ΓòÉΓòÉΓòÉ
  3696.  
  3697. Perform a parse 
  3698.  
  3699. SYNTAX:             void lr_parse_open(LR_P **P, LR2 *lr, char *text, char 
  3700.                     *path, long stack_size); 
  3701.  
  3702. PARAMETERS: 
  3703.  
  3704.    LR_P **P            Pointer to pointer to parse result. 
  3705.  
  3706.    LR2 *lr             Pointer to condensed version of LR-parsing table. 
  3707.  
  3708.    char *text          Text to be parsed. 
  3709.  
  3710.    char *path          Path where will be placed resulting files. If path is 0, 
  3711.                        the files will be located in the current working 
  3712.                        directory. Empty line implies root directory. 
  3713.  
  3714. EFFECT:             Parses text 'text' using LR-parsing table 'lr' with stack 
  3715.                     size = 'stack_size' placing parse result in 'P' and file 
  3716.                     <<NAME>>.prs placed in path 'path'. 
  3717.  
  3718. RETURN:             Nothing. 
  3719.  
  3720.  
  3721. ΓòÉΓòÉΓòÉ 10.3.4. lr_print_parse - print parse results  ΓòÉΓòÉΓòÉ
  3722.  
  3723.  SYNTAX: 
  3724.                      void  lr_print_parse    (LR_P *p); 
  3725.  
  3726.  PARAMETERS: 
  3727.  
  3728.     LR_P *p  pointer to parse results. 
  3729.  
  3730.  EFFECT: 
  3731.                      Print parse result p to file <<NAME>>.PRS 
  3732.  
  3733.  RETURN: 
  3734.                      Nothing. 
  3735.  
  3736.  
  3737. ΓòÉΓòÉΓòÉ 10.3.5. lr_parse_free  - release the results of a parse ΓòÉΓòÉΓòÉ
  3738.  
  3739. Release the results of a parse 
  3740.  
  3741. SYNTAX:             void lr_parse_free (LR_P  *P); 
  3742.  
  3743. PARAMETERS: 
  3744.  
  3745.    LR_P *P             pointer to parse results. 
  3746.  
  3747. EFFECT:             Releases memory allocated by 'lr_parse_open'. 
  3748.  
  3749. RETURN:             Nothing. 
  3750.  
  3751.  
  3752. ΓòÉΓòÉΓòÉ <hidden> Parse tree navigation primitives ΓòÉΓòÉΓòÉ
  3753.  
  3754.  To navigate parse tree there are several program primitives and data 
  3755. structures: 
  3756.  
  3757. o lrx_n 
  3758. o lrx_loc 
  3759. o lrx_one 
  3760. o lrx_zero 
  3761. o lrx_add 
  3762. o lrx_all 
  3763. o lrx_zap 
  3764. o lrx_up 
  3765. o lrx_copy 
  3766. o lrx_list_do 
  3767. o lrx_tree_do 
  3768.  
  3769.  
  3770. ΓòÉΓòÉΓòÉ 11. Breakpoint Technique of LR ΓòÉΓòÉΓòÉ
  3771.  
  3772.  
  3773. ΓòÉΓòÉΓòÉ 11.1. Quick start into Breakpoint Technique of LR ΓòÉΓòÉΓòÉ
  3774.  
  3775.                  Quick Start to the Breakpoint Technique of LR.
  3776.  
  3777. What is breakpoint technique (BT)? 
  3778.  
  3779. BT is the thing that allows you to process parse tree dynamically. What does it 
  3780. mean? This means that you can control the parse process and the creation of the 
  3781. parse tree during parsing. 
  3782.  
  3783. Basic structure for breakpoint processing is breakpoint set (BS). BS is the set 
  3784. various breakpoints and global semantic action (it will be will be discussed 
  3785. later). 
  3786.  
  3787. The breakpoints that are in BS fall into two categories : nonterminal 
  3788. breakpoints and special breakpoints. 
  3789.  
  3790. Nonterminal breakpoints are those invoked by construction of nonterminals. E.g. 
  3791. when the LR-parser reduces something to a nonterminal it will look through BS 
  3792. for the breakpoint that is bounded with this nonterminal ("bounding" with 
  3793. nonterminal means that any nonterminal breakpoint has number that is equal with 
  3794. the number of the nonterminal to which the breakpoint is "bounded" (see 
  3795. STR-file and N-files  about number of nonterminal)), if the semantic action for 
  3796. this breakpoint exists the parser will execute the breakpoint and will continue 
  3797. parsing, else the parser'll check is the breakpoint active or not, if yes then 
  3798. the parser will try to do global semantic action but if it does not exist too 
  3799. then the parser will do nothing, and after that all the parser will continue 
  3800. parsing. 
  3801.  
  3802. The second type of breakpoints is (as mentioned above) special breakpoints. 
  3803. There are three special breakpoints : 
  3804.  
  3805. o start breakpoint, 
  3806. o end-of-file breakpoint, 
  3807. o error breakpoint. 
  3808.  
  3809. Start breakpoint will be executed in the beginning of parsing process. 
  3810.  
  3811. End-of-file breakpoint will be executed when the parser will encounter the end 
  3812. of input file. 
  3813.  
  3814. Error breakpoint will be executed when a syntax error will be detected. 
  3815.  
  3816. Now about breakpoint execution. I think you wonder what is the 'breakpoint 
  3817. execution'. Every breakpoint (it does not matter either nonterminal or special) 
  3818. has: 
  3819.  
  3820. o pointer to the parse tree node where the breakpoint is being executed, 
  3821. o pointer to a semantic action and switches. 
  3822.  
  3823. The pointer to the parse tree node means : pointer to the parse tree node that 
  3824. is the nonterminal to which the breakpoint was bounded (for nonterminal 
  3825. breakpoints), or the parse tree node where start or end of file was encountered 
  3826. or a syntax error was detected (for special breakpoints). 
  3827.  
  3828. The pointer to a semantic action means pointer to the function with special 
  3829. prototype (it is explained in the 'lr_bp_*' functions description) that will be 
  3830. executed if the switches will be in definite states. 
  3831.  
  3832. The switches. If stop switch is set on then the semantic action of this 
  3833. breakpoint will be executed, else the semantic action will not be executed. If 
  3834. stop switch is set on then the parsing process will be interrupted, continue 
  3835. information will be written to BS and control will be returned to the caller of 
  3836. 'lr_bp_parse*' function. 
  3837.  
  3838. Execution of a breakpoint means : checking switches and calling or not calling 
  3839. the semantic action for the breakpoint (the pointer to the parse tree node will 
  3840. be passed to the semantic action; see 'lr_bp_*' functions' description for 
  3841. prototypes and examples) according to current states of the switches. 
  3842.  
  3843. About global semantic action from BS. This semantic action will be executed for 
  3844. invoked breakpoint if the breakpoint is active and has no own semantic action. 
  3845.  
  3846. Now briefly repeat all of the above and add some additional information. 
  3847.  
  3848. There is breakpoint set that contains set of user-defined nonterminal 
  3849. breakpoints, special breakpoints and global semantic action. 
  3850.  
  3851. A nonterminal breakpoint contains pointer, action and switches. By default 
  3852. there is no semantic action in a created breakpoint, but user can define it 
  3853. using 'lr_bp_*' functions. It is desirable to set switches to needed states (of 
  3854. course using 'lr_bp_*' macros) because their default value may not satisfy you. 
  3855.  
  3856. Note: 
  3857.  
  3858. There is one remark about BS : when we say nonterminal we mean not the concrete 
  3859. nonterminal but class of concrete parse tree nodes that are associated with, 
  3860. for example nonterminal IF in grammar definition; so there may be only one 
  3861. breakpoint associated with one nonterminal (so this breakpoint will be executed 
  3862. on every just reduced parse tree node that was reduced to the nonterminal 
  3863. marked with the breakpoint). 
  3864.  
  3865. To use BT you must do following steps: 
  3866.  
  3867.  1. Create BS: 
  3868.  
  3869.    o lr_bp_init 
  3870.  
  3871.  2. Initialize needed breakpoints with switches and semantic actions: 
  3872.  
  3873.    o lr_bp_*_on; 
  3874.    o lr_bp_*_off; 
  3875.    o lr_bp_command_*; 
  3876.    o lr_bp_feed*; 
  3877.    o lr_bp_register_command. 
  3878.  
  3879.  3. Parse text: 
  3880.  
  3881.    o lr_bp_parse_open. 
  3882.  
  3883.  4. If control was returned to you (stop switches in some breakpoints were set 
  3884.     on) then you can do something and/or continue parsing and/or do nothing: 
  3885.  
  3886.    o lr_bp_next; 
  3887.    o lr_bp_start; 
  3888.    o lr_bp_reduce; 
  3889.    o lr_bp_go. 
  3890.  
  3891.  5. Free memory used by BS: 
  3892.  
  3893.    o lr_bp_free. 
  3894.  
  3895.  
  3896. ΓòÉΓòÉΓòÉ <hidden> lr_bp_*_off ΓòÉΓòÉΓòÉ
  3897.  
  3898. o lr_bp_active_off; 
  3899. o lr_bp_stop_off; 
  3900. o lr_bp_start_off; 
  3901. o lr_bp_eof_off; 
  3902. o lr_bp_error_off; 
  3903. o lr_bp_switch_off; 
  3904. o lr_bp_command_off. 
  3905.  
  3906.  
  3907. ΓòÉΓòÉΓòÉ <hidden> lr_bp_*_on ΓòÉΓòÉΓòÉ
  3908.  
  3909. o lr_bp_active_on; 
  3910. o lr_bp_stop_on; 
  3911. o lr_bp_start_on; 
  3912. o lr_bp_eof_on; 
  3913. o lr_bp_error_on; 
  3914. o lr_bp_switch_on; 
  3915. o lr_bp_command_on. 
  3916.  
  3917.  
  3918. ΓòÉΓòÉΓòÉ <hidden> lr_bp_command_* ΓòÉΓòÉΓòÉ
  3919.  
  3920. o lr_bp_command_on; 
  3921. o lr_bp_command_off; 
  3922. o lr_bp_command_active; 
  3923. o lr_bp_command_start; 
  3924. o lr_bp_command_eof; 
  3925. o lr_bp_command_err. 
  3926.  
  3927.  
  3928. ΓòÉΓòÉΓòÉ <hidden> lr_bp_feed* ΓòÉΓòÉΓòÉ
  3929.  
  3930. o lr_bp_feed; 
  3931. o lr_bp_feed_active. 
  3932.  
  3933.  
  3934. ΓòÉΓòÉΓòÉ 11.2. Prototype of semantic action. ΓòÉΓòÉΓòÉ
  3935.  
  3936. Protoype of a semantic action: 
  3937.  
  3938. An example of semantic action prototype: 
  3939.  
  3940. void cmd(LR_BPT *);
  3941.  
  3942. An example of array of semantic actions: 
  3943.  
  3944. void (**cmd_vec)(LR_BPT *);
  3945.  
  3946.  
  3947. ΓòÉΓòÉΓòÉ 11.3. Basic types of LR Breakpoint Technique. ΓòÉΓòÉΓòÉ
  3948.  
  3949. Basic types of LR Breakpoint Technique are: 
  3950.  
  3951. LR_BPT - type of breakpoint (struct); 
  3952. LR_BP  - type of breakpoint set (struct); 
  3953.  
  3954. EXAMPLES: 
  3955.  
  3956. An example of semantic action prototype: 
  3957.  
  3958. void cmd(LR_BPT *);
  3959.  
  3960. An example of array of semantic actions: 
  3961.  
  3962. void (**cmd_vec)(LR_BPT *);
  3963.  
  3964. An example of pointer to a breakpoint: 
  3965.  
  3966. LR_BPT *pBPT;
  3967.  
  3968. An example of pointer to a breakpoint set: 
  3969.  
  3970. LR_BP *pBP;
  3971.  
  3972.  
  3973. ΓòÉΓòÉΓòÉ 11.4. lr_bp_field - direct write to breakpoint structure  ΓòÉΓòÉΓòÉ
  3974.  
  3975.  SYNTAX: 
  3976.                      lr_bp_field(LR_BP *_BP, long _n, _field, _value); 
  3977.  
  3978.  PARAMETERS: 
  3979.  
  3980.     _BP           pointer to a breakpoint set; 
  3981.     _n            number of needed breakpoint; 
  3982.     _field        name of needed field; 
  3983.     _value        value to send (by '='operation) to the specified field 
  3984.                   ('value' must have the same type as 'field'); 
  3985.  
  3986.  EFFECT: 
  3987.                      Write value '_value' in the field '_field' of a breakpoint 
  3988.                     handler that is located in breakpoint set '*(_BP)' by 
  3989.                     number '_n'. 
  3990.  
  3991.  RETURN: 
  3992.                      Nothing. 
  3993.  
  3994.  
  3995. Basic LR Breakpoint Technique types. 
  3996.  
  3997.  
  3998. ΓòÉΓòÉΓòÉ 11.5. lr_bp_n - get number of breakpoint  ΓòÉΓòÉΓòÉ
  3999.  
  4000.  SYNTAX: 
  4001.                      lr_bp_n(LR_BPT *_BPT); 
  4002.  
  4003.  PARAMETERS: 
  4004.  
  4005.     _BPT          pointer to a breakpoint; 
  4006.  
  4007.  EFFECT: 
  4008.                      Obtain number of the breakpoint. 
  4009.  
  4010.  RETURN: 
  4011.                      Number of the breakpoint. 
  4012.  
  4013.  
  4014. Basic LR Breakpoint Technique types. 
  4015.  
  4016.  
  4017. ΓòÉΓòÉΓòÉ 11.6. lr_bp_do - scan breakpoint set  ΓòÉΓòÉΓòÉ
  4018.  
  4019.  SYNTAX: 
  4020.                      lr_bp_do(LR_BP *_BP); 
  4021.  
  4022.  PARAMETERS: 
  4023.  
  4024.     _BP           pointer to a breakpoint set; 
  4025.  
  4026.  EFFECT: 
  4027.                      Scans breakpoint set '*(_BP)'. Work counter is 
  4028.                     (_BP)->bptc. 
  4029.  
  4030.  RETURN: 
  4031.                      Nothing. 
  4032.  
  4033.  EXAMPLE: 
  4034.  
  4035.                                           lr_bp_do(pTEST_BP)
  4036.                                             {
  4037.                                               lr_bp_field(pTEST_BP,pTEST_BP->bptc,isactive,1)
  4038.                                             }
  4039.  
  4040.                     This example will scan all *(pTEST_BP) and will make all 
  4041.                     breakpoints in it active. 
  4042.  
  4043.  
  4044. Basic LR Breakpoint Technique types. 
  4045.  
  4046.  
  4047. ΓòÉΓòÉΓòÉ 11.7. lr_bp_bpt - obtain pointer to predefined breakpoint  ΓòÉΓòÉΓòÉ
  4048.  
  4049.  SYNTAX: 
  4050.                      lr_bp_bpt(LR_BP *_BP, NAME ); 
  4051.  
  4052.  PARAMETERS: 
  4053.  
  4054.     _BP           pointer to breakpoint set; 
  4055.     _NAME         one of this -> {start, eof, err}; 
  4056.  
  4057.  EFFECT: 
  4058.                      Obtain pointer to predefined breakpoint. 
  4059.  
  4060.  RETURN: 
  4061.                      Pointer to the specified breakpoint handler. 
  4062.  
  4063.  EXAMPLE: 
  4064.  
  4065.                                         start_breakpoint = lr_bp_bpt(pTEST_BP,start);
  4066.  
  4067.                     This example will assign pointer to the start breakpoint 
  4068.                     handler to 'start_breakpoint'. 
  4069.  
  4070.  
  4071. Basic LR Breakpoint Technique types. 
  4072.  
  4073.  
  4074. ΓòÉΓòÉΓòÉ 11.8. lr_bp_active_on - set breakpoint switch 'active'on  ΓòÉΓòÉΓòÉ
  4075.  
  4076.  SYNTAX: 
  4077.                      lr_bp_active_on(LR_BP *_BP, long _n); 
  4078.  
  4079.  PARAMETERS: 
  4080.  
  4081.     _BP           pointer to a breakpoint set; 
  4082.     _n            number of needed breakpoint in the breakpoint set; 
  4083.  
  4084.  EFFECT: 
  4085.                      Turns on the 'isactive' switch in the breakpoint handler 
  4086.                     number '_n' in '*(_BP)'. 
  4087.  
  4088.  RETURN: 
  4089.                      Nothing. 
  4090.  
  4091.  EXAMPLE: 
  4092.  
  4093.                                         lr_bp_active_on(pTEST_BP, 34);
  4094.  
  4095.                     This example will turn on the 'isactive' switch in the 
  4096.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4097.  
  4098.  
  4099. Basic LR Breakpoint Technique types. 
  4100.  
  4101.  
  4102. ΓòÉΓòÉΓòÉ 11.9. lr_bp_active_off - set breakpoint switch 'active'off  ΓòÉΓòÉΓòÉ
  4103.  
  4104.  SYNTAX: 
  4105.                      lr_bp_active_off(LR_BP *_BP, long _n); 
  4106.  
  4107.  PARAMETERS: 
  4108.  
  4109.     _BP           pointer to a breakpoint set; 
  4110.     _n            number of needed breakpoint in the breakpoint set; 
  4111.  
  4112.  EFFECT: 
  4113.                      Turns off the 'isactive' switch in the breakpoint handler 
  4114.                     number '_n' in '*(_BP)'. 
  4115.  
  4116.  RETURN: 
  4117.                      Nothing. 
  4118.  
  4119.  NOTES: 
  4120.  
  4121.  
  4122.  EXAMPLE: 
  4123.  
  4124.                                         lr_bp_active_off(pTEST_BP, 34);
  4125.  
  4126.                     This example will turn off the 'isactive' switch in the 
  4127.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4128.  
  4129.  
  4130. Basic LR Breakpoint Technique types. 
  4131.  
  4132.  
  4133. ΓòÉΓòÉΓòÉ 11.10. lr_bp_stop_on - set breakpoint switch 'stop'on  ΓòÉΓòÉΓòÉ
  4134.  
  4135.  SYNTAX: 
  4136.                      lr_bp_stop_on(LR_BP *_BP, long _n); 
  4137.  
  4138.  PARAMETERS: 
  4139.  
  4140.     _BP           pointer to a breakpoint set; 
  4141.     _n            number of needed breakpoint in the breakpoint set; 
  4142.  
  4143.  EFFECT: 
  4144.                      Turn on the 'isstop' switch in the breakpoint handler 
  4145.                     number '_n' in '*(_BP)'. 
  4146.  
  4147.  RETURN: 
  4148.                      Nothing. 
  4149.  
  4150.  EXAMPLE: 
  4151.  
  4152.                                         lr_bp_stop_on(pTEST_BP, 34);
  4153.  
  4154.                     This example will turn on the 'isstop' switch in the 
  4155.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4156.  
  4157.  
  4158. Basic LR Breakpoint Technique types. 
  4159.  
  4160.  
  4161. ΓòÉΓòÉΓòÉ 11.11. lr_bp_stop_off - set breakpoint switch 'stop'off  ΓòÉΓòÉΓòÉ
  4162.  
  4163.  SYNTAX: 
  4164.                      lr_bp_stop_off(LR_BP *_BP, long _n); 
  4165.  
  4166.  PARAMETERS: 
  4167.  
  4168.     _BP           pointer to a breakpoint set; 
  4169.     _n            number of needed breakpoint in the breakpoint set; 
  4170.  
  4171.  EFFECT: 
  4172.                      Turn off the 'isstop' switch in the breakpoint handler 
  4173.                     number '_n' in '*(_BP)'. 
  4174.  
  4175.  RETURN: 
  4176.                      Nothing. 
  4177.  
  4178.  EXAMPLE: 
  4179.  
  4180.                                         lr_bp_stop_off(pTEST_BP, 34);
  4181.  
  4182.                     This example will turn off the 'isstop' switch in the 
  4183.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4184.  
  4185.  
  4186. Basic LR Breakpoint Technique types. 
  4187.  
  4188.  
  4189. ΓòÉΓòÉΓòÉ 11.12. lr_bp_start_on - set breakpoint switch 'start'on  ΓòÉΓòÉΓòÉ
  4190.  
  4191.  SYNTAX: 
  4192.                      lr_bp_start_on(LR_BP *_BP, long _n); 
  4193.  
  4194.  PARAMETERS: 
  4195.  
  4196.     _BP           pointer to a breakpoint set; 
  4197.     _n            number of needed breakpoint in the breakpoint set; 
  4198.  
  4199.  EFFECT: 
  4200.                      Turn on the 'isstart' switch in the breakpoint handler 
  4201.                     number '_n' in '*(_BP)'. 
  4202.  
  4203.  RETURN: 
  4204.                      Nothing. 
  4205.  
  4206.  EXAMPLE: 
  4207.  
  4208.                                         lr_bp_start_on(pTEST_BP, 34);
  4209.  
  4210.                     This example will turn on the 'isstart' switch in the 
  4211.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4212.  
  4213.  
  4214. Basic LR Breakpoint Technique types. 
  4215.  
  4216.  
  4217. ΓòÉΓòÉΓòÉ 11.13. lr_bp_start_off - set breakpoint switch 'start'off  ΓòÉΓòÉΓòÉ
  4218.  
  4219.  SYNTAX: 
  4220.                      lr_bp_start_off(LR_BP *_BP, long _n); 
  4221.  
  4222.  PARAMETERS: 
  4223.  
  4224.     _BP           pointer to a breakpoint set; 
  4225.     _n             in the breakpoint set; 
  4226.  
  4227.  EFFECT: 
  4228.                      Turn off the 'isstart' switch in the breakpoint handler 
  4229.                     number '_n' in '*(_BP)'. 
  4230.  
  4231.  RETURN: 
  4232.                      Nothing. 
  4233.  
  4234.  EXAMPLE: 
  4235.                      Example of usage - 
  4236.  
  4237.                                         lr_bp_start_off(pTEST_BP, 34);
  4238.  
  4239.                     This example will turn off the 'isstart' switch in the 
  4240.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4241.  
  4242.  
  4243. Basic LR Breakpoint Technique types. 
  4244.  
  4245.  
  4246. ΓòÉΓòÉΓòÉ 11.14. lr_bp_eof_on - set breakpoint switch 'eof'on  ΓòÉΓòÉΓòÉ
  4247.  
  4248.  SYNTAX: 
  4249.                      lr_bp_eof_on(LR_BP *_BP, long _n); 
  4250.  
  4251.  PARAMETERS: 
  4252.  
  4253.     _BP           pointer to a breakpoint set; 
  4254.     _n            number of needed breakpoint in the breakpoint set; 
  4255.  
  4256.  EFFECT: 
  4257.                      Turns on the 'iseof' switch in the breakpoint handler 
  4258.                     number '_n' in '*(_BP)'. 
  4259.  
  4260.  RETURN: 
  4261.                      Nothing. 
  4262.  
  4263.  EXAMPLE: 
  4264.  
  4265.                                         lr_bp_eof_on(pTEST_BP, 34);
  4266.  
  4267.                     This example will turn on the 'iseof' switch in the 
  4268.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4269.  
  4270.  
  4271. Basic LR Breakpoint Technique types. 
  4272.  
  4273.  
  4274. ΓòÉΓòÉΓòÉ 11.15. lr_bp_eof_off - set breakpoint switch 'eof'off  ΓòÉΓòÉΓòÉ
  4275.  
  4276.  SYNTAX: 
  4277.                      lr_bp_eof_off(LR_BP *_BP, long _n); 
  4278.  
  4279.  PARAMETERS: 
  4280.  
  4281.     _BP           pointer to a breakpoint set; 
  4282.     _n            number of needed breakpoint in the breakpoint set; 
  4283.  
  4284.  EFFECT: 
  4285.                      Turns off the 'iseof' switch in the breakpoint handler 
  4286.                     number '_n' in '*(_BP)'. 
  4287.  
  4288.  RETURN: 
  4289.                      Nothing. 
  4290.  
  4291.  EXAMPLE: 
  4292.  
  4293.                                         lr_bp_eof_off(pTEST_BP, 34);
  4294.  
  4295.                     This example will turn off the 'iseof' switch in the 
  4296.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4297.  
  4298.  
  4299. Basic LR Breakpoint Technique types. 
  4300.  
  4301.  
  4302. ΓòÉΓòÉΓòÉ 11.16. lr_bp_error_on - set breakpoint switch 'error'on  ΓòÉΓòÉΓòÉ
  4303.  
  4304.  SYNTAX: 
  4305.                      lr_bp_error_on(LR_BP *_BP, long _n); 
  4306.  
  4307.  PARAMETERS: 
  4308.  
  4309.     _BP           pointer to a breakpoint set; 
  4310.     _n            number of needed breakpoint in the breakpoint set; 
  4311.  
  4312.  EFFECT: 
  4313.                      Turns on the 'iserr' switch in the breakpoint handler 
  4314.                     number '_n' in '*(_BP)'. 
  4315.  
  4316.  RETURN: 
  4317.                      Nothing. 
  4318.  
  4319.  EXAMPLE: 
  4320.  
  4321.                                         lr_bp_error_on(pTEST_BP, 34);
  4322.  
  4323.                     This example will turn on the 'iserr' switch in the 
  4324.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4325.  
  4326.  
  4327. Basic LR Breakpoint Technique types. 
  4328.  
  4329.  
  4330. ΓòÉΓòÉΓòÉ 11.17. lr_bp_error_off - set breakpoint switch 'error'off  ΓòÉΓòÉΓòÉ
  4331.  
  4332.  SYNTAX: 
  4333.                      lr_bp_error_off(LR_BP *_BP, long _n); 
  4334.  
  4335.  PARAMETERS: 
  4336.  
  4337.     _BP           pointer to a breakpoint set; 
  4338.     _n            number of needed breakpoint in the breakpoint set; 
  4339.  
  4340.  EFFECT: 
  4341.                      Turns off the 'iserr' switch in the breakpoint handler 
  4342.                     number '_n' in '*(_BP)'. 
  4343.  
  4344.  RETURN: 
  4345.                      Nothing. 
  4346.  
  4347.  EXAMPLE: 
  4348.  
  4349.                                         lr_bp_error_off(pTEST_BP, 34);
  4350.  
  4351.                     This example will turn off the 'iserr' switch in the 
  4352.                     breakpoint handler number 34 in '*(pTEST_BP)'. 
  4353.  
  4354.  
  4355. Basic LR Breakpoint Technique types. 
  4356.  
  4357.  
  4358. ΓòÉΓòÉΓòÉ 11.18. lr_bp_switch_on - set breakpoint switches 'active'and 'stop_here'on  ΓòÉΓòÉΓòÉ
  4359.  
  4360.  SYNTAX: 
  4361.                      lr_bp_switch_on(LR_BP *_BP, long _n); 
  4362.  
  4363.  PARAMETERS: 
  4364.  
  4365.     _BP           pointer to a breakpoint set; 
  4366.     _n            number of needed breakpoint in the breakpoint set; 
  4367.  
  4368.  EFFECT: 
  4369.                      Turns on the 'isactive' and 'stop_here' switches in the 
  4370.                     breakpoint handler number '_n' in '*(_BP)'. 
  4371.  
  4372.  RETURN: 
  4373.                      Nothing. 
  4374.  
  4375.  EXAMPLE: 
  4376.  
  4377.                                         lr_bp_switch_on(pTEST_BP, 34);
  4378.  
  4379.                     This example will turn on the 'isactive' and 'stop_here' 
  4380.                     switches in the breakpoint handler number 34 in 
  4381.                     '*(pTEST_BP)'. 
  4382.  
  4383.  
  4384. Basic LR Breakpoint Technique types. 
  4385.  
  4386.  
  4387. ΓòÉΓòÉΓòÉ 11.19. lr_bp_switch_off - set breakpoint switches 'active'and 'stop_here'off  ΓòÉΓòÉΓòÉ
  4388.  
  4389.  SYNTAX: 
  4390.                      lr_bp_switch_off(LR_BP *_BP, long _n); 
  4391.  
  4392.  PARAMETERS: 
  4393.  
  4394.     _BP           pointer to a breakpoint set; 
  4395.     _n            number of needed breakpoint in the breakpoint set; 
  4396.  
  4397.  EFFECT: 
  4398.                      Turns off the 'isactive' and 'stop_here' switches in the 
  4399.                     breakpoint handler number '_n' in '*(_BP)'. 
  4400.  
  4401.  RETURN: 
  4402.                      Nothing. 
  4403.  
  4404.  EXAMPLE: 
  4405.  
  4406.                                         lr_bp_switch_off(pTEST_BP, 34);
  4407.  
  4408.                     This example will turn off the 'isactive' and 'stop_here' 
  4409.                     switches in the breakpoint handler number 34 in 
  4410.                     '*(pTEST_BP)'. 
  4411.  
  4412.  
  4413. Basic LR Breakpoint Technique types. 
  4414.  
  4415.  
  4416. ΓòÉΓòÉΓòÉ 11.20. lr_bp_command_on - set semantic action to a breakpoint  ΓòÉΓòÉΓòÉ
  4417.  
  4418.  SYNTAX: 
  4419.                      lr_bp_command_on(LR_BP *_BP, long _n, void _cmd(LR_BPT 
  4420.                     *)); 
  4421.  
  4422.  PARAMETERS: 
  4423.  
  4424.     _BP           pointer to a breakpoint set; 
  4425.     _n            number of needed breakpoint in given breakpoint set; 
  4426.     _cmd          semantic action ; 
  4427.  
  4428.  EFFECT: 
  4429.                      It will assign semantic action '_cmd' to breakpoint 
  4430.                     handler by number '_n' in breakpoint set '*(_BP)'. 
  4431.  
  4432.  RETURN: 
  4433.                      Nothing. 
  4434.  
  4435.  EXAMPLE: 
  4436.  
  4437.                                         lr_bp_command_on(pTEST_BP,34,cmd);
  4438.  
  4439.                     This example will set 'cmd' semantic action to the 
  4440.                     breakpoint handler by number 34 that is located in 
  4441.                     breakpoint set '*(pTEST_BP)'. 
  4442.  
  4443.  
  4444. Basic LR Breakpoint Technique types. 
  4445.  
  4446.  
  4447. ΓòÉΓòÉΓòÉ 11.21. lr_bp_command_off - delete semantic action from a breakpoint  ΓòÉΓòÉΓòÉ
  4448.  
  4449.  SYNTAX: 
  4450.                      lr_bp_command_off(LR_BP *_BP, long _n); 
  4451.  
  4452.  PARAMETERS: 
  4453.  
  4454.     _BP           pointer to a breakpoint set; 
  4455.     _n            number of needed breakpoint in given breakpoint set; 
  4456.     _cmd          semantic action 
  4457.  
  4458.  EFFECT: 
  4459.                      It will zero (set NULL pointer to) semantic action field 
  4460.                     in to breakpoint handler by number '_n' in breakpoint set 
  4461.                     '*(_BP)'. 
  4462.  
  4463.  RETURN: 
  4464.                      Nothing. 
  4465.  
  4466.  EXAMPLE: 
  4467.  
  4468.                                         lr_bp_command_off(pTEST_BP,34);
  4469.  
  4470.                     This example will set semantic action of breakpoint handler 
  4471.                     by number 34 that is located in breakpoint set 
  4472.                     '*(pTEST_BP)' to zero ( no semantic action will be executed 
  4473.                     if breakpoint number 34 will be encountered ). 
  4474.  
  4475.  
  4476. Basic LR Breakpoint Technique types. 
  4477.  
  4478.  
  4479. ΓòÉΓòÉΓòÉ 11.22. lr_bp_command_active - set semantic action to a breakpoint and makes the breakpoint active  ΓòÉΓòÉΓòÉ
  4480.  
  4481.  SYNTAX: 
  4482.                      lr_bp_command_active(LR_BP *_BP, long _n, void _cmd(LR_BPT 
  4483.                     *)); 
  4484.  
  4485.  PARAMETERS: 
  4486.  
  4487.     _BP           pointer to a breakpoint set; 
  4488.     _n            number of needed breakpoint in given breakpoint set; 
  4489.     _cmd          semantic action 
  4490.  
  4491.  EFFECT: 
  4492.                      It will assign semantic action '_cmd' to breakpoint 
  4493.                     handler by number '_n' in breakpoint set '*(_BP)' and make 
  4494.                     this breakpoint active (by setting 'isactive' switch to 1). 
  4495.  
  4496.  RETURN: 
  4497.                      Nothing. 
  4498.  
  4499.  EXAMPLE: 
  4500.  
  4501.                                         lr_bp_command_active(pTEST_BP,34,cmd);
  4502.  
  4503.                     This example will set semantic action 'cmd' to breakpoint 
  4504.                     handler by number 34 that is located in breakpoint set 
  4505.                     '*(pTEST_BP)'. 
  4506.  
  4507.  
  4508. Basic LR Breakpoint Technique types. 
  4509.  
  4510.  
  4511. ΓòÉΓòÉΓòÉ 11.23. lr_bp_command_start - set semantic action to start breakpoint  ΓòÉΓòÉΓòÉ
  4512.  
  4513.  SYNTAX: 
  4514.                      lr_bp_command_start(LR_BP *_BP, void _cmd(LR_BPT *)); 
  4515.  
  4516.  PARAMETERS: 
  4517.  
  4518.     _BP           pointer to a breakpoint set; 
  4519.     _n            number of the needed breakpoint in given breakpoint set; 
  4520.     _cmd          semantic action 
  4521.  
  4522.  EFFECT: 
  4523.                      It will assign semantic action '_cmd' to the 
  4524.                     start-breakpoint of breakpoint set '*(_BP)'. 
  4525.  
  4526.  RETURN: 
  4527.                      Nothing. 
  4528.  
  4529.  EXAMPLE: 
  4530.  
  4531.                                         lr_bp_command_start(pTEST_BP,cmd);
  4532.  
  4533.                     This example will set semantic action 'cmd' to start 
  4534.                     breakpoint handler that is located in breakpoint set 
  4535.                     '*(pTEST_BP)'. 
  4536.  
  4537.  
  4538. Basic LR Breakpoint Technique types. 
  4539.  
  4540.  
  4541. ΓòÉΓòÉΓòÉ 11.24. lr_bp_command_eof - set semantic action to eof breakpoint  ΓòÉΓòÉΓòÉ
  4542.  
  4543.  SYNTAX: 
  4544.                      lr_bp_command_eof(LR_BP *_BP, void _cmd(LR_BPT *)); 
  4545.  
  4546.  PARAMETERS: 
  4547.  
  4548.     _BP           pointer to a breakpoint set; 
  4549.     _n            number of the needed breakpoint in given breakpoint set; 
  4550.     _cmd          semantic action 
  4551.  
  4552.  EFFECT: 
  4553.                      It will assign semantic action '_cmd' to the 
  4554.                     eof-breakpoint (end of file breakpoint) of breakpoint set 
  4555.                     '*(_BP)'. 
  4556.  
  4557.  RETURN: 
  4558.                      Nothing. 
  4559.  
  4560.  EXAMPLE: 
  4561.  
  4562.                                         lr_bp_command_eof(pTEST_BP,cmd);
  4563.  
  4564.                     This example will set semantic action 'cmd' to eof 
  4565.                     breakpoint handler that is located in breakpoint set 
  4566.                     '*(pTEST_BP)'. 
  4567.  
  4568.  
  4569. Basic LR Breakpoint Technique types. 
  4570.  
  4571.  
  4572. ΓòÉΓòÉΓòÉ 11.25. lr_bp_command_err - set semantic action to error breakpoint  ΓòÉΓòÉΓòÉ
  4573.  
  4574.  SYNTAX: 
  4575.                      lr_bp_command_err(LR_BP *_BP, void _cmd(LR_BPTT *)); 
  4576.  
  4577.  PARAMETERS: 
  4578.  
  4579.     _BP           pointer to a breakpoint set; 
  4580.     _n            number of the needed breakpoint in given breakpoint set; 
  4581.     _cmd          semantic action 
  4582.  
  4583.  EFFECT: 
  4584.                      It will assign semantic action '_cmd' to the error 
  4585.                     breakpoint of breakpoint set '*(_BP)'. 
  4586.  
  4587.  RETURN: 
  4588.                      Nothing. 
  4589.  
  4590.  EXAMPLE: 
  4591.  
  4592.                                         lr_bp_command_off(pTEST_BP,cmd);
  4593.  
  4594.                     This example will set semantic action 'cmd' to error 
  4595.                     breakpoint handler that is located in breakpoint set 
  4596.                     '*(pTEST_BP)'. 
  4597.  
  4598.  
  4599. Basic LR Breakpoint Technique types. 
  4600.  
  4601.  
  4602. ΓòÉΓòÉΓòÉ 11.26. lr_bp_feed - feed array of semantics into breakpoint set  ΓòÉΓòÉΓòÉ
  4603.  
  4604.  SYNTAX: 
  4605.                      lr_bp_feed(LR_BP *_BP, void (**_CMDS)(LR_BPT *)); 
  4606.  
  4607.  PARAMETERS: 
  4608.  
  4609.     _BP           pointer to a breakpoint set; 
  4610.     _CMDS         an array of semantic actions 
  4611.  
  4612.  EFFECT: 
  4613.                      'lr_bp_feed' will assign semantic actions to all 
  4614.                     breakpoints in '*(_BP)'. The semantic actions will be taken 
  4615.                     from array '_CMDS'. The semantic action (_CMDS)[0] will be 
  4616.                     assigned to the breakpoint number 0, the semantic action 
  4617.                     (_CMDS)[1] will be assigned to the breakpoint number 1 etc. 
  4618.                     If number of breakpoints is larger than number of defined 
  4619.                     elements in '_CMDS' then junk will be written instead of 
  4620.                     semantic actions in last breakpoints. 
  4621.  
  4622.  RETURN: 
  4623.                      Nothing. 
  4624.  
  4625.  EXAMPLE: 
  4626.  
  4627.                                         lr_bp_feed(pTEST_BP, SActions);
  4628.  
  4629.                     This example will assign actions from 'SActions' to all 
  4630.                     breakpoints from breakpoint set '*(pTEST_BP)'. 
  4631.  
  4632.  
  4633. Basic LR Breakpoint Technique types. 
  4634.  
  4635.  
  4636. ΓòÉΓòÉΓòÉ 11.27. lr_bp_feed_active - feed array of semantics into breakpoint set and make all fed breakpoints active  ΓòÉΓòÉΓòÉ
  4637.  
  4638.  SYNTAX: 
  4639.                      lr_bp_feed_active(LR_BP *_BP, void (**_CMDS)(LR_BPT *)); 
  4640.  
  4641.  PARAMETERS: 
  4642.  
  4643.     _BP           pointer to a breakpoint set; 
  4644.     _CMDS         an array of semantic actions 
  4645.  
  4646.  EFFECT: 
  4647.                      'lr_bp_feed_active' will do the same action as 
  4648.                     'lr_bp_feed' but in addition it will make all breakpoints 
  4649.                     in '*(_BP)' active (by setting 'isactive' switch to 1). 
  4650.  
  4651.  RETURN: 
  4652.                      Nothing. 
  4653.  
  4654.  EXAMPLE: 
  4655.  
  4656.                                         lr_bp_feed_active(pTEST_BP, SActions);
  4657.  
  4658.                     This example will assign actions from 'SActions' to all 
  4659.                     breakpoints from breakpoint set '*(pTEST_BP)' and will make 
  4660.                     all breakpoints in '*(pTEST_BP)' active. 
  4661.  
  4662.  
  4663. Basic LR Breakpoint Technique types. 
  4664.  
  4665.  
  4666. ΓòÉΓòÉΓòÉ 11.28. lr_bp_register_command - register global semantic  ΓòÉΓòÉΓòÉ
  4667.  
  4668.  SYNTAX: 
  4669.                      lr_bp_register_command(LR_BP *_BP, void _cmd(LR_BPT *)); 
  4670.  
  4671.  PARAMETERS: 
  4672.  
  4673.     _BP           pointer to a breakpoint set; 
  4674.     _cmd          semantic action 
  4675.  
  4676.  EFFECT: 
  4677.                      It will register semantic action '_cmd' as global semantic 
  4678.                     action for breakpoint set '*(_BP)'. 
  4679.  
  4680.  RETURN: 
  4681.                      Nothing. 
  4682.  
  4683.  EXAMPLE: 
  4684.  
  4685.                                         lr_bp_register_command(pTEST_BP, GlobalAction);
  4686.  
  4687.                     This example will register semantic action 'GlobalAction' 
  4688.                     as global semantic action for breakpoint set '*(pTEST_BP)'. 
  4689.  
  4690.  
  4691. Basic LR Breakpoint Technique types. 
  4692.  
  4693.  
  4694. ΓòÉΓòÉΓòÉ 11.29. lr_bp_go - go until needed breakpoint will be encountered  ΓòÉΓòÉΓòÉ
  4695.  
  4696.  SYNTAX: 
  4697.                      lr_bp_go(LR_BPT *_BPT_S, long _n); 
  4698.  
  4699.  PARAMETERS: 
  4700.  
  4701.     _BPT_S        pointer to a breakpoint; 
  4702.     _n            number of the breakpoint; where to stop; 
  4703.  
  4704.  EFFECT: 
  4705.                      It will start parsing from the breakpoint '*(_BPT_S)' to 
  4706.                     the breakpoint with the number '_n' 
  4707.  
  4708.  RETURN: 
  4709.                      Nothing. 
  4710.  
  4711.  
  4712. Basic LR Breakpoint Technique types. 
  4713.  
  4714.  
  4715. ΓòÉΓòÉΓòÉ 11.30. lr_bp_init - create breakpoint set  ΓòÉΓòÉΓòÉ
  4716.  
  4717.  SYNTAX: 
  4718.                      LR_BP *lr_bp_init(char *grammar2); 
  4719.  
  4720.  PARAMETERS: 
  4721.  
  4722.     grammar2      name of file containing condensed grammar; 
  4723.  
  4724.  EFFECT: 
  4725.                      Creates a new breakpoint set and initializes it with a 
  4726.                     condensed grammar that is located in file 'grammar2'. 
  4727.  
  4728.  RETURN: 
  4729.                      Pointer to the initialized breakpoint set, or 0 (zero) if 
  4730.                     the specified file can not be opened. 
  4731.  
  4732.  NOTES: 
  4733.                      By default, no breakpoint has a semantic. Predefined 
  4734.                     breakpoints 'bpt_start', 'bpt_eof' and 'bpt_err' are 
  4735.                     active. 'bpt_eof' and 'bpt_err' are stop breakpoints. 
  4736.  
  4737.  
  4738. Basic LR Breakpoint Technique types. 
  4739.  
  4740.  
  4741. ΓòÉΓòÉΓòÉ 11.31. lr_bp_start - start parsing from specified position using breakpoint set  ΓòÉΓòÉΓòÉ
  4742.  
  4743.  SYNTAX: 
  4744.                      LR_BPT *lr_bp_start(LR_BP *bp, char *text); 
  4745.  
  4746.  PARAMETERS: 
  4747.  
  4748.     bp            pointer to a breakpoint set; 
  4749.     text          ASCIIZ (null terminated) character string of text to be 
  4750.                   parsed; 
  4751.  
  4752.  EFFECT: 
  4753.                      It will start parsing of 'text' using breakpoint set 
  4754.                     '*(bp)'and stop on first active stop breakpoint from 
  4755.                     '*(bp)' 
  4756.  
  4757.  RETURN: 
  4758.                      Pointer to the breakpoint which stopped the parsing. 
  4759.  
  4760.  NOTES: 
  4761.                      If there were the results of previous parsing (field 
  4762.                     bp->lp is nonzero), the function at first releases them. 
  4763.  
  4764.  
  4765. Basic LR Breakpoint Technique types. 
  4766.  
  4767.  
  4768. ΓòÉΓòÉΓòÉ 11.32. lr_bp_reduce - perform single reduction  ΓòÉΓòÉΓòÉ
  4769.  
  4770.  SYNTAX: 
  4771.                      LR_BPT *lr_bp_reduce(LR_BP *bp, LR2_S **S, char **C, char 
  4772.                     **c, char *sc, LR_BPTS s, long n); 
  4773.  
  4774.  PARAMETERS: 
  4775.  
  4776.     bp            pointer to a breakpoint set; 
  4777.     S             address of pointer to current LR-automaton state; 
  4778.     C             pointer to text at which reduction starts; 
  4779.     c             pointer to text at which reduction stops; 
  4780.     sc            text parsed from the previous break; 
  4781.     s             breakpoint state; 
  4782.     n             breakpoint reduction counter; 
  4783.  
  4784.  EFFECT: 
  4785.                      Performs a single reduction considering breakpoint set. 
  4786.  
  4787.  RETURN: 
  4788.                      Pointer to encountered breakpoint, or 0 (zero) if the 
  4789.                     reduction doesn't lead to break (correspondent breakpoint 
  4790.                     is inactive). 
  4791.  
  4792.  
  4793. Basic LR Breakpoint Technique types. 
  4794.  
  4795.  
  4796. ΓòÉΓòÉΓòÉ 11.33. lr_bp_next - continue parsing until next breakpoint  ΓòÉΓòÉΓòÉ
  4797.  
  4798.  SYNTAX: 
  4799.                      LR_BPT *lr_bp_next(LR_BPT *bpt); 
  4800.  
  4801.  PARAMETERS: 
  4802.  
  4803.     bpt           pointer to a breakpoint; 
  4804.  
  4805.  EFFECT: 
  4806.                      It will continue the parsing from the breakpoint 'bpt' 
  4807.                     until next breakpoint. 
  4808.  
  4809.  RETURN: 
  4810.                      Returns pointer to the next encountered breakpoint. 
  4811.  
  4812.  
  4813. Basic LR Breakpoint Technique types. 
  4814.  
  4815.  
  4816. ΓòÉΓòÉΓòÉ 11.34. lr_bp_free - delete breakpoint set from memory  ΓòÉΓòÉΓòÉ
  4817.  
  4818.  SYNTAX: 
  4819.                      void lr_bp_free(LR_BP *bp); 
  4820.  
  4821.  PARAMETERS: 
  4822.  
  4823.     bp            pointer to a breakpoint set; 
  4824.  
  4825.  EFFECT: 
  4826.                      Deletes breakpoint set '*(bp)' from memory. 
  4827.  
  4828.  RETURN: 
  4829.                      Nothing. 
  4830.  
  4831.  NOTES: 
  4832.                      After this function 'bp' will point to undefined place!!! 
  4833.                     So BE CAREFULL!!! 
  4834.  
  4835.  
  4836. Basic LR Breakpoint Technique types. 
  4837.  
  4838.  
  4839. ΓòÉΓòÉΓòÉ 11.35. lr_bp_error - default error semantic  ΓòÉΓòÉΓòÉ
  4840.  
  4841.  SYNTAX: 
  4842.                      void lr_bp_error(LR_BPT *bpt); 
  4843.  
  4844.  PARAMETERS: 
  4845.  
  4846.     bpt           pointer to error breakpoint handler; 
  4847.  
  4848.  EFFECT: 
  4849.                      It will print parse errors to <<GRAMMAR_NAME>>.ERR file 
  4850.                     where <<GRAMMAR_NAME>> is the name of the grammar according 
  4851.                     to which the input text file was parsed. It is default 
  4852.                     error breakpoint semantics. 
  4853.  
  4854.  RETURN: 
  4855.                      Nothing. 
  4856.  
  4857.  NOTES: 
  4858.                      This routine is recommended to be used in run-time 
  4859.                     semantics. 
  4860.  
  4861.  EXAMPLE: 
  4862.  
  4863.                                         lr_bp_command_err(bp, lr_bp_error);
  4864.  
  4865.  
  4866.  
  4867.  
  4868. Basic LR Breakpoint Technique types. 
  4869.  
  4870.  
  4871. ΓòÉΓòÉΓòÉ 11.36. lr_bp_parse_open - perform parsing of a text using a grammar  ΓòÉΓòÉΓòÉ
  4872.  
  4873.  SYNTAX: 
  4874.                      LR_P *lr_bp_parse_open(char *grammar2,char *text,char 
  4875.                     *file); 
  4876.  
  4877.  PARAMETERS: 
  4878.  
  4879.     grammar2      name of file where condensed grammar is located; 
  4880.     text          pointer to an area in memory where text to be parsed is 
  4881.                   located; 
  4882.     file          name of file from where the 'text' was loaded (used in 
  4883.                   construction of names of .PRS etc. files); 
  4884.  
  4885.  EFFECT: 
  4886.                      Reads grammar from file with name stored in 'grammar2', 
  4887.                     parses text from 'text' using the loaded grammar and 
  4888.                     outputs results in file with name stored in 'file' 
  4889.  
  4890.  RETURN: 
  4891.                      Pointer to parse results (parse tree), or 0 (zero) if the 
  4892.                     file with the condensed grammar can not be opened. 
  4893.  
  4894.  
  4895. Basic LR Breakpoint Technique types. 
  4896.  
  4897.  
  4898. ΓòÉΓòÉΓòÉ 12. Technical Support ΓòÉΓòÉΓòÉ
  4899.  
  4900. Technical Support may be obtained by contacting: 
  4901.  
  4902.                     Philip R Brenan at Compuserve 71022, 3620
  4903.  
  4904.  
  4905. ΓòÉΓòÉΓòÉ 13. Grammar of a simple sequences ΓòÉΓòÉΓòÉ
  4906.  
  4907. This grammar defines the syntax of a simple sequences. 
  4908.  
  4909. LR
  4910.   (
  4911.      NAME(SQNS_1)
  4912.      TITLE('Sequences 1.')
  4913.      PATH
  4914.      STRUCT
  4915.      PRINT
  4916.      RULES
  4917.      (
  4918.         sequence    ( alpha item ( zero ) end_of_seq)
  4919.  
  4920.         item        (alpha)
  4921.                     (omega)
  4922.  
  4923.         alpha       ('abcd'(choice mixed))
  4924.  
  4925.         omega       ('123456789'(choice))
  4926.  
  4927.         end_of_seq  ('.')
  4928.       )
  4929.  
  4930.     )
  4931.  
  4932.                     Grammar definition of a simple sequences.
  4933.  
  4934. See also 
  4935.  
  4936. o Parsing tree of a simple sequence , 
  4937.  
  4938. o STR-file and N-file . 
  4939.  
  4940.  
  4941. ΓòÉΓòÉΓòÉ 14. Example of usage of "do everything" procedure (lr_sql.c) ΓòÉΓòÉΓòÉ
  4942.  
  4943.  
  4944. /*
  4945. ______________________________________________________________________________
  4946. Example LR processing
  4947. Philip R Brenan, Transcendental Automation, 1993, CompuServe 71022,3620
  4948. ______________________________________________________________________________
  4949. */
  4950. #include "lrx.inc"           //01 Include this file in all parsing programs
  4951. #include "lr_sql.str"        //02 Generated declarations for SQL
  4952. #include "lr_sql.cc"         //03 Generated load procedures for SQL
  4953.  
  4954. lrx_cmd(lr_sql_print);       //04 Generic print routine for any non terminal
  4955. lrx_cmd(lr_sql_ts_options);  //05 Print routine for create tablespace options
  4956. /*
  4957. _______________________________________________________________________________
  4958. Parse the sql in LR_SQL.SQL and print each non terminal
  4959. _______________________________________________________________________________
  4960. */
  4961. int main(void)               //06 Main procedure
  4962.  {LRX_REQ    r;              //07 Request structure to lrx_req
  4963.   LR_SQL_cmd cmd;            //08 Procedures to implement non terminals for SQL
  4964.   LR_SQL_NPS nps;            //09 Non terminal work area for SQL
  4965.   int        i, j;           //10 Counters
  4966.  
  4967.   r.pre  = cmd.pre;          //11 Initialize pointer to pre commands for SQL
  4968.   r.post = 0;                //12 No post commands
  4969.   r.nps  = &nps;            //13 Initialize pointer to Non terminal Pointer Set work area for SQL
  4970. /*
  4971. _______________________________________________________________________________
  4972. Load print routine into each non terminal's pre command - must initialize each
  4973. semantic routine pointer, or set to zero.  r.post will be zero and hence ignored.
  4974. _______________________________________________________________________________
  4975. */
  4976.   for(i = 0; i < LR_SQL_n; ++i)           //14 For each non terminal in SQL
  4977.    {cmd.pre[i] = lr_sql_print;            //15 Set print routine as semantic action
  4978.    }
  4979.   cmd.pre[LR_SQL_CREATE_TS_OPTIONS_n] = lr_sql_ts_options;
  4980.                                           //16 Load semantic action for specific non terminal
  4981. /*
  4982. _______________________________________________________________________________
  4983. Request parse of the sql in LR_SQL.SQL and print each non terminal
  4984. _______________________________________________________________________________
  4985. */
  4986.   r.text_file    = "lr_sql.sql";          //17 Name the input filer
  4987.   r.grammar_file = "lr_sql.lrs";          //18 Name grammar file
  4988.   r.req          = lrx_req_load_grammar | //19 Load grammar
  4989.                    lrx_req_load_text    | //20 Load text
  4990.                    lrx_req_parse        | //21 Parse text with grammar
  4991.                    lrx_req_print_parse  | //22 Print parse tree
  4992.                    lrx_req_free_all;      //23 Free all parse resources
  4993. /*
  4994. _______________________________________________________________________________
  4995. Perform parse and exit
  4996. _______________________________________________________________________________
  4997. */
  4998.   lrx_req(&r);                           //24 Perform requests
  4999.  }
  5000. /*
  5001. _______________________________________________________________________________
  5002. Generic Semantic action
  5003. REQ - request list
  5004. PT  - Non terminal pointer
  5005. _______________________________________________________________________________
  5006. */
  5007. lrx_cmd(lr_sql_print)                     //25 Generic print
  5008.  {printf("%s", PT->k);                    //26 Print non terminal name
  5009.   if (PT->t)                              //27 If non terminal has a value
  5010.     printf(" = %s", PT->t);               //28 Print associated value
  5011.   printf("\n");                           //29 New line
  5012.  }
  5013. /*
  5014. _______________________________________________________________________________
  5015. Put a non terminal - lrx_concat concatenates all the text under the given
  5016. non terminal
  5017. _______________________________________________________________________________
  5018. */
  5019. void lr_sql_put(LR_PT *pt)                  //30 Put a non terminal
  5020.  {char   c[256];                            //31 Character buffer
  5021.  
  5022.   if (pt) printf("%s ", lrx_concat(c, pt)); //32 Print non terminal if present
  5023.  }
  5024. /*
  5025. _______________________________________________________________________________
  5026. CREATE_TS_OPTIONS semantic action.
  5027. Get addressability to non terminals beneath current non terminal, and print them
  5028.  
  5029. REQ - request list - from main procedure
  5030. PT  - Non terminal pointer
  5031. _______________________________________________________________________________
  5032. */
  5033. lrx_cmd(lr_sql_ts_options)                   //33 Process CREATE_TS_OPTIONS non terminal
  5034.  {LR_SQL_NT_CREATE_TS_OPTIONS a;             //34 Pointers to this non terminal's immediate decendents
  5035.  
  5036.   LR_SQL_LOAD_NT_CREATE_TS_OPTIONS(&a, PT); //35 Get addressability to non terminals dependents
  5037.  
  5038.   lr_sql_put(a.FREEPAGE);                    //36 Print FREEPAGE
  5039.   lr_sql_put(a.PCTFREE);                     //37 Print PCTFREE
  5040.   lr_sql_put(a.BUFFERPOOL3);                 //38 Print BUFFERPOOL
  5041.   lr_sql_put(a.LOCKSIZE);                    //39 Print LOCKSIZE
  5042.   lr_sql_put(a.CLOSE);                       //40 Print CLOSE
  5043.   printf("\n");                              //41 New line
  5044.  }
  5045.  
  5046.  
  5047. ΓòÉΓòÉΓòÉ 15. Sample of LR application ΓòÉΓòÉΓòÉ
  5048.  
  5049. #include "sample.h"
  5050. /*
  5051.  ΓòöΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòù
  5052.  Γòæ Copyright (C) Transcendental Automation, 1993.                             Γòæ
  5053.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5054.  Γòæ SAMPLE.C - The main file of project.                                       Γòæ
  5055.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5056.  Γòæ This file contains next functions:                                         Γòæ
  5057.  Γòæ                                                                            Γòæ
  5058.  Γòæ void main(void)                                                            Γòæ
  5059.  Γòæ void InitAll(char *s) - Initialize all resources and load file passed as   Γòæ
  5060.  Γòæ                         first argument of prgram or (if nothing was passed Γòæ
  5061.  Γòæ                         to programm) 'sample.txt'.                         Γòæ
  5062.  Γòæ                                                                            Γòæ
  5063.  Γòæ void FreeAll(void)   - Rlease all resources                                Γòæ
  5064.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5065.  Γòæ Description of program:                                                    Γòæ
  5066.  Γòæ This program is an interpreter of simple grammar.                          Γòæ
  5067.  Γòæ First program initialize stack of float , vartable ,load compiled grammar  Γòæ
  5068.  Γòæ and so on. Then it launch parsing of the text contained in file passed as  Γòæ
  5069.  Γòæ argument or 'sample.txt'.Then program free all allocated resources.        Γòæ
  5070.  ΓòÜΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓò¥
  5071.  
  5072. Requred files:
  5073.  
  5074.       TABLE.C
  5075.  
  5076.       COMMANDS.C
  5077.  
  5078.       SAMPLE.H
  5079.  
  5080.       SAMPLE.MAK
  5081.  
  5082.       SAMPLE.GR
  5083.  
  5084.  */
  5085.  
  5086. LRSAF cmd[SAMPLE_n];
  5087. SAMPLE_PT NTPS;             // nonterminal pointer set
  5088. LR2      *grammar;          // Pointer to compiled grammar
  5089.  
  5090. void    InitAll(char *);
  5091. void    FreeAll();
  5092. char    *text;              // text to parse
  5093.  
  5094. /*
  5095. ___________________________________________________________________________
  5096.  The main function
  5097. ___________________________________________________________________________
  5098. */
  5099. int main(int e,char **s)
  5100.  {puts("Copyright (C) Transcendental Automation, 1993.");
  5101.   if(s[1]==0)
  5102.     puts("Usage : sample [input_file]");
  5103.   InitAll(s[1]);
  5104.   puts("Processing...");                                                                                                /**/
  5105.   lrx_parse(0,0,cmd,(LRX_PT*)&NTPS,grammar,text,STACK_SIZE,0);//launch parsing of text
  5106.                                                       //then semantics action.                                                                                                /**/
  5107.   FreeAll();
  5108. }
  5109. /*
  5110. ______________________________________________________________________________
  5111.  This function initializes all needed resources.
  5112. ______________________________________________________________________________
  5113. */
  5114. void InitAll(char *name)
  5115.  {//initialize internal tables.
  5116.   InitTable       (); // initializing vartable.
  5117.   InitFloatStack  (); // initializing stack of floats.
  5118.   InitCmdTable    (); // initializing table of semantic actions.                                                                                               /**/
  5119.   lr2_open(&grammar,"sample.lrs"); //open compiled grammar
  5120.   text = u_load_ds( name ? name : "sample.txt" );//load file to memory                                                                                                                                     /**/
  5121.   printf("Input file : %s\n",name ? name : "sample.txt");
  5122.   if(!text)
  5123.    {puts("Error : unable to open input file.");
  5124.     exit(3452);
  5125.    }
  5126.   puts("Input text :");
  5127.   puts(text);
  5128.  }
  5129.  
  5130. /*
  5131. ______________________________________________________________________________
  5132.  This function releases all allocated resources.
  5133. ______________________________________________________________________________
  5134. */
  5135.  
  5136. void  FreeAll(void)                                                                              /**/
  5137.  {u_free_ds(text);    // free alocated memory
  5138.   lr2_free(grammar);  // release compiled grammar                                                                                 /**/
  5139.   FreeTable       (); // free vartable.
  5140.   FreeFloatStack  (); // freestack of floats
  5141.  }
  5142.  
  5143.  
  5144. ΓòÉΓòÉΓòÉ <hidden> Sample_h ΓòÉΓòÉΓòÉ
  5145.  
  5146. #ifndef __SAMPLE_H
  5147. #define __SAMPLE_H
  5148. /*
  5149.  ΓòöΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòù
  5150.  Γòæ Copyright (C) Transcendental Automation, 1993.                           Γòæ
  5151.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5152.  Γòæ SAMPLE.H                                                                 Γòæ
  5153.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5154.  Γòæ This file is used by all modules and contains all necessary definitions  Γòæ
  5155.  Γòæ and declarations                                                         Γòæ
  5156.  ΓòÜΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓò¥
  5157. */
  5158. #include <io.h>
  5159. #include <lrx.inc>
  5160. #include <process.h>
  5161. #include "sample.str"
  5162.  
  5163. #define STACK_SIZE 1000                       // size of stack of automaton.
  5164.  
  5165. typedef void(*LRSAF)(void*,SAMPLE_PT*,LR_PT*);// type of semantic action.
  5166.  
  5167. extern LRSAF cmd[SAMPLE_n]; //table of semantic action(LRSAF - LR Semantic Action Function).
  5168. void  InitCmdTable();       //initialization of this table
  5169.  
  5170. extern SAMPLE_PT NTPS;      // nonterminal pointer set
  5171. extern LR2      *grammar;   // Pointer to compiled grammar
  5172.  
  5173. void    InitTable (void);   // see table.c for more information about these
  5174. float   LookUp    (char*);  // functions.
  5175. void    SetItem   (char*,float);
  5176. void    FreeTable (void);
  5177.  
  5178. void    InitFloatStack  (void);
  5179. void    pushFloat        (float);
  5180. float   popFloat        (void);
  5181. void    FreeFloatStack  (void);
  5182.  
  5183. #endif
  5184.  
  5185.  
  5186. ΓòÉΓòÉΓòÉ <hidden> Sample_str ΓòÉΓòÉΓòÉ
  5187.  
  5188. #ifndef SAMPLE_PT_INC
  5189. #define SAMPLE_PT_INC
  5190. /*
  5191. ______________________________________________________________________________
  5192. Nonterminal parse items for SAMPLE grammar
  5193. ______________________________________________________________________________
  5194. */
  5195. typedef struct SAMPLE_PT
  5196.  {LR_PT *l;
  5197.   LR_P  *p;
  5198.   LR_PT *key[29];
  5199.  } SAMPLE_PT;
  5200. #define                       SAMPLE_ADD(_T) ((_T).l = (_T).key[0])
  5201. #define                       SAMPLE_ADD_n                      0
  5202. #define                     SAMPLE_ALPHA(_T) ((_T).l = (_T).key[1])
  5203. #define                     SAMPLE_ALPHA_n                      1
  5204. #define             SAMPLE_ALPHA_NUMERIC(_T) ((_T).l = (_T).key[2])
  5205. #define             SAMPLE_ALPHA_NUMERIC_n                      2
  5206. #define                    SAMPLE_ASSIGN(_T) ((_T).l = (_T).key[3])
  5207. #define                    SAMPLE_ASSIGN_n                      3
  5208. #define                   SAMPLE_ASSIGNS(_T) ((_T).l = (_T).key[4])
  5209. #define                   SAMPLE_ASSIGNS_n                      4
  5210. #define                     SAMPLE_DIGIT(_T) ((_T).l = (_T).key[5])
  5211. #define                     SAMPLE_DIGIT_n                      5
  5212. #define                       SAMPLE_DIV(_T) ((_T).l = (_T).key[6])
  5213. #define                       SAMPLE_DIV_n                      6
  5214. #define                         SAMPLE_E(_T) ((_T).l = (_T).key[7])
  5215. #define                         SAMPLE_E_n                      7
  5216. #define                       SAMPLE_EXP(_T) ((_T).l = (_T).key[8])
  5217. #define                       SAMPLE_EXP_n                      8
  5218. #define                         SAMPLE_F(_T) ((_T).l = (_T).key[9])
  5219. #define                         SAMPLE_F_n                      9
  5220. #define                     SAMPLE_FLOAT(_T) ((_T).l = (_T).key[10])
  5221. #define                     SAMPLE_FLOAT_n                      10
  5222. #define                SAMPLE_IDENTIFIER(_T) ((_T).l = (_T).key[11])
  5223. #define                SAMPLE_IDENTIFIER_n                      11
  5224. #define                       SAMPLE_MUL(_T) ((_T).l = (_T).key[12])
  5225. #define                       SAMPLE_MUL_n                      12
  5226. #define                       SAMPLE_NEG(_T) ((_T).l = (_T).key[13])
  5227. #define                       SAMPLE_NEG_n                      13
  5228. #define                         SAMPLE_S(_T) ((_T).l = (_T).key[14])
  5229. #define                         SAMPLE_S_n                      14
  5230. #define                      SAMPLE_SIGN(_T) ((_T).l = (_T).key[15])
  5231. #define                      SAMPLE_SIGN_n                      15
  5232. #define                       SAMPLE_SUB(_T) ((_T).l = (_T).key[16])
  5233. #define                       SAMPLE_SUB_n                      16
  5234. #define                         SAMPLE_T(_T) ((_T).l = (_T).key[17])
  5235. #define                         SAMPLE_T_n                      17
  5236. #define                    SAMPLE__DIGIT(_T) ((_T).l = (_T).key[18])
  5237. #define                    SAMPLE__DIGIT_n                      18
  5238. #define                       SAMPLE__e_(_T) ((_T).l = (_T).key[19])
  5239. #define                       SAMPLE__e__n                      19
  5240. #define                     SAMPLE_point(_T) ((_T).l = (_T).key[27])
  5241. #define                     SAMPLE_point_n                      27
  5242. #define                           SAMPLE_n                      29
  5243.  
  5244. #endif
  5245.  
  5246.  
  5247. ΓòÉΓòÉΓòÉ <hidden> Table_c ΓòÉΓòÉΓòÉ
  5248.  
  5249. #include "sample.h"
  5250. #include <malloc.h>
  5251. /*
  5252.  ΓòöΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòù
  5253.  Γòæ Copyright (C) Transcendental Automation, 1993.                             Γòæ
  5254.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5255.  Γòæ TABLE.C                                                                    Γòæ
  5256.  Γòæ This file contains sourse code of functions:                               Γòæ
  5257.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5258.  Γòæ Work with table of variables                                               Γòæ
  5259.  Γòæ      void    InitTable (void)    - initialize vartable.                    Γòæ
  5260.  Γòæ      float   LookUp    (char* nm) - search in vartable variable with name  Γòæ
  5261.  Γòæ                                     'nm' if not found create new variabe inΓòæ
  5262.  Γòæ                                     vartable and set it with zero.         Γòæ
  5263.  Γòæ                                                                            Γòæ
  5264.  Γòæ      void    AddItem   (char*t,float f) - add new var named 'nm'to vartableΓòæ
  5265.  Γòæ                                           and set it with 'f'.             Γòæ
  5266.  Γòæ      void    SetItem   (char* t,float f) - set var named 'nm' with 'f'.    Γòæ
  5267.  Γòæ      void    FreeTable (void)            - free resources allocated by     Γòæ
  5268.  Γòæ                                            vartable                        Γòæ
  5269.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5270.  Γòæ Work with stack of floats                                                  Γòæ
  5271.  Γòæ      void    pushFloat       (float f) - put 'f' to stack                  Γòæ
  5272.  Γòæ      float   popFloat        (void)    - get 'f' from stack                Γòæ
  5273.  Γòæ      void    FreeFloatStack  ()        - free stack                        Γòæ
  5274.  Γòæ      void    InitFloatStack  ()        - initialize stack                  Γòæ
  5275.  ΓòÜΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓò¥
  5276.  */
  5277. /*
  5278. _____________________________________________________________________________
  5279.  VARTABLE SECTION
  5280. _____________________________________________________________________________
  5281. */
  5282. /*
  5283. _____________________________________________________________________________
  5284.  The structure 'VarTableItem' represents element of vartable.
  5285. _____________________________________________________________________________
  5286. */
  5287.  
  5288. struct VarTableItem
  5289.  {char* name;                   // the name of variable
  5290.   float val;                    // the value of variable
  5291.   struct VarTableItem *next;    // pointer to next variable
  5292.  };
  5293.  
  5294. static struct VarTableItem* FList; //pointer to the first variable in the table.
  5295.  
  5296. /*
  5297. ______________________________________________________________________________
  5298.  Initialize vartable
  5299. ______________________________________________________________________________
  5300.  */
  5301. void    InitTable (void)
  5302.  {FList = 0;
  5303.  }
  5304.  
  5305. void    AddItem   (char*t,float f);
  5306. /*
  5307. _____________________________________________________________________________
  5308.  Look up variable in the vartable and return its value if found or
  5309.  add variable with value 0 to vartable and return 0.
  5310. _____________________________________________________________________________
  5311. */
  5312. float   LookUp    (char* nm)
  5313.  {struct VarTableItem *cur;
  5314.   cur = FList;
  5315.   while ( cur && stricmp(cur->name,nm) )
  5316.     cur = cur -> next;
  5317.  
  5318.   if ( cur == 0)
  5319.    {AddItem(nm,0);
  5320.     return 0;
  5321.    }
  5322.   else
  5323.    return cur->val;
  5324.  }
  5325. /*
  5326. _____________________________________________________________________________
  5327.  Add item to vartable.
  5328. _____________________________________________________________________________
  5329. */
  5330. void    AddItem   (char*t,float f)
  5331.  {struct VarTableItem *cur = malloc(sizeof(struct VarTableItem));
  5332.   cur->next   = FList;
  5333.   cur->name   = strdup(t);
  5334.   strupr(cur->name);
  5335.   cur->val    = f;
  5336.   FList = cur;
  5337.  }
  5338. /*
  5339. _____________________________________________________________________________
  5340.  Set item named 't' with f
  5341. _____________________________________________________________________________
  5342. */
  5343. void    SetItem   (char* t,float f)
  5344.  {struct VarTableItem *cur = FList;
  5345.   while ( cur && stricmp(cur->name,t) )   cur = cur -> next;
  5346.   if ( cur == 0)
  5347.     AddItem(t,f);
  5348.   else
  5349.     cur->val = f;
  5350.  }
  5351. /*
  5352. _____________________________________________________________________________
  5353.  Release memory allocated by vartable and print results of calculations
  5354. _____________________________________________________________________________
  5355. */
  5356. void    FreeTable (void)
  5357.  {struct VarTableItem *cur = FList ,*x;
  5358.   puts("Calculations has been finished.");
  5359.   puts("Results:");
  5360.   puts("Name         Value.");
  5361.   while ( cur )
  5362.    {x=cur;
  5363.     cur = cur -> next;
  5364.     printf("%-12.12s %g\n",x->name,x->val);
  5365.     free (x);
  5366.    }
  5367.   FList = 0;
  5368.  }
  5369.  
  5370. /*
  5371. _____________________________________________________________________________
  5372.  FLOAT STACK SECTION
  5373. _____________________________________________________________________________
  5374. */
  5375.  
  5376. /*
  5377. _____________________________________________________________________________
  5378.  The structure represent a item of float stack.
  5379. _____________________________________________________________________________
  5380. */
  5381.  
  5382. static struct FLOAT_EL
  5383.  {float val;             // value of the item
  5384.   struct FLOAT_EL *next; // pointer to the next item
  5385.  } *FStack;              // pointer to the top of the stack
  5386.  
  5387. /*
  5388. ______________________________________________________________________________
  5389.  Initialize the stack of floats
  5390. ______________________________________________________________________________
  5391. */
  5392. void    InitFloatStack  ()
  5393.  {FStack = 0;
  5394.  }
  5395. /*
  5396. ______________________________________________________________________________
  5397.  Push float 'f' to the stack.
  5398. ______________________________________________________________________________
  5399. */
  5400. void    pushFloat       (float f)
  5401.  {struct FLOAT_EL *cur = malloc(sizeof(struct FLOAT_EL));
  5402.   cur->next   = FStack;
  5403.   cur->val    = f;
  5404.   FStack      = cur;
  5405.  }
  5406.  
  5407. /*
  5408. ______________________________________________________________________________
  5409.  Pop float from the stack.
  5410. ______________________________________________________________________________
  5411. */
  5412. float   popFloat        (void)
  5413.  {if(FStack)
  5414.    {struct FLOAT_EL *cur;
  5415.     float r;
  5416.     r=FStack->val;
  5417.     cur = FStack->next;
  5418.     free(FStack);
  5419.     FStack = cur;
  5420.     return r;
  5421.    }
  5422.   puts("\'popFloat\':The Stack is empty");
  5423.   exit(666);
  5424.   return 0;
  5425.  }
  5426. /*
  5427. _____________________________________________________________________________
  5428.  if the stack is not empty free it.
  5429. _____________________________________________________________________________
  5430. */
  5431. void    FreeFloatStack   ()
  5432.  {struct FLOAT_EL *cur = FStack ,*x;
  5433.   while ( cur )
  5434.    {x=cur;
  5435.     cur = cur -> next;
  5436.     free (x);
  5437.    }
  5438.   FStack = 0;
  5439.  }
  5440.  
  5441.  
  5442. ΓòÉΓòÉΓòÉ <hidden> Commands_c ΓòÉΓòÉΓòÉ
  5443.  
  5444. /*
  5445.  ΓòöΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòù
  5446.  Γòæ Copyright (C) Transcendental Automation, 1993.                            Γòæ
  5447.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5448.  Γòæ COMMANDS.C                                                                Γòæ
  5449.  ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5450.  Γòæ This module contains the function that initializes semantic actions' tableΓòæ
  5451.  Γòæ and functions which define this semantic actions.All semantics action     Γòæ
  5452.  Γòæ work in the time of postfix traversal.                                    Γòæ
  5453.  ΓòÜΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓò¥
  5454. */
  5455. #include "sample.h"
  5456. #include <stdio.h>
  5457.  
  5458. void ASSIGN_func     (void*,SAMPLE_PT*,LR_PT*);
  5459. void DIV_func        (void*,SAMPLE_PT*,LR_PT*);
  5460. void MUL_func        (void*,SAMPLE_PT*,LR_PT*);
  5461. void ADD_func        (void*,SAMPLE_PT*,LR_PT*);
  5462. void SUB_func        (void*,SAMPLE_PT*,LR_PT*);
  5463. void NEG_func        (void*,SAMPLE_PT*,LR_PT*);
  5464. void FLOAT_func      (void*,SAMPLE_PT*,LR_PT*);
  5465. void IDENTIFIER_func (void*,SAMPLE_PT*,LR_PT*);
  5466. /*
  5467. _____________________________________________________________________________
  5468.  Initialize table of semantic actions
  5469. _____________________________________________________________________________
  5470. */
  5471. void InitCmdTable()
  5472.  {int i;
  5473.   for(i=0;i<SAMPLE_n;i++) cmd [i] = 0;
  5474.   cmd[SAMPLE_ASSIGN_n]        = ASSIGN_func;
  5475.   cmd[SAMPLE_DIV_n]           = DIV_func;
  5476.   cmd[SAMPLE_MUL_n]           = MUL_func;
  5477.   cmd[SAMPLE_ADD_n]           = ADD_func;
  5478.   cmd[SAMPLE_SUB_n]           = SUB_func;
  5479.   cmd[SAMPLE_NEG_n]           = NEG_func;
  5480.   cmd[SAMPLE_FLOAT_n]         = FLOAT_func;
  5481.   cmd[SAMPLE_IDENTIFIER_n]    = IDENTIFIER_func;
  5482.  }
  5483.  
  5484. /*
  5485. ______________________________________________________________________________
  5486.  The function realize semantics of assign
  5487. _____________________________________________________________________________
  5488. */
  5489. static void ASSIGN_func     (void* sysp, SAMPLE_PT* NPS, LR_PT* pt)
  5490.  {LR_PT* zt = pt->PL.f->d;      // the RHS of rule ASSIGN contain 3 nonterminals
  5491.                                 // so the first son always exists.
  5492.                                 // 'pt->PL.f->d' means pointer to first son.
  5493.  
  5494.   if(zt->t && lrx_n(zt) == SAMPLE_IDENTIFIER_n) //test if first son is identifier
  5495.    {SetItem(zt->t,popFloat()); // the top of stack is value of expression
  5496.     popFloat();                // the top of stack is value of identifier before
  5497.                                // calculation.
  5498.    }
  5499.  }
  5500.  
  5501. /*
  5502. ______________________________________________________________________________
  5503.  The function realize semantics of division.
  5504. _____________________________________________________________________________
  5505. */
  5506. static void DIV_func        (void* sysp, SAMPLE_PT* NPS, LR_PT* pt)
  5507.  {float a = popFloat();
  5508.   if(a==0)
  5509.    {puts("Divide by zero.");
  5510.     exit(4);
  5511.    }
  5512.   pushFloat(popFloat()/a);
  5513.  }
  5514.  
  5515. /*
  5516. ______________________________________________________________________________
  5517.  The function realize semantics of multiplication
  5518. _____________________________________________________________________________
  5519. */
  5520. static void MUL_func        (void* sysp, SAMPLE_PT* NPS, LR_PT* pt)
  5521.  {pushFloat( popFloat() * popFloat() );
  5522.  }
  5523.  
  5524. /*
  5525. ______________________________________________________________________________
  5526.  The function realize semantics of addition
  5527. _____________________________________________________________________________
  5528. */
  5529. static void ADD_func        (void* sysp, SAMPLE_PT* NPS, LR_PT* pt)
  5530.  {pushFloat( popFloat() + popFloat() );
  5531.  }
  5532.  
  5533. /*
  5534. ______________________________________________________________________________
  5535.  The function realize semantics of subtraction
  5536. _____________________________________________________________________________
  5537. */
  5538. static void SUB_func        (void* sysp, SAMPLE_PT* NPS, LR_PT* pt)
  5539.  {pushFloat( - popFloat() + popFloat() );
  5540.  }
  5541.  
  5542. /*
  5543. ______________________________________________________________________________
  5544.  The function realize semantics of negation
  5545. _____________________________________________________________________________
  5546. */
  5547. static void NEG_func        (void* sysp, SAMPLE_PT* NPS, LR_PT* pt)
  5548.  {pushFloat( - popFloat());
  5549.  }
  5550.  
  5551. /*
  5552. ______________________________________________________________________________
  5553.  The function realize semantics of constant
  5554. _____________________________________________________________________________
  5555. */
  5556. static void FLOAT_func      (void* sysp, SAMPLE_PT* NPS, LR_PT* pt)
  5557.  {pushFloat(atof(pt->t));
  5558.  }
  5559.  
  5560. /*
  5561. ______________________________________________________________________________
  5562.  The function realize semantics of identifier
  5563. _____________________________________________________________________________
  5564. */
  5565. static void IDENTIFIER_func (void* sysp, SAMPLE_PT* NPS, LR_PT* pt)
  5566.  {pushFloat(LookUp(pt->t));
  5567.  }
  5568.  
  5569.  
  5570. ΓòÉΓòÉΓòÉ <hidden> Sample_mak ΓòÉΓòÉΓòÉ
  5571.  
  5572.  
  5573. #ΓòöΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòù
  5574. #Γòæ Copyright (C)  Transcendental Automation ,1993.                          Γòæ
  5575. #ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5576. #Γòæ SAMPLE.MAK                                                               Γòæ
  5577. #ΓòƒΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓòó
  5578. #Γòæ This makefile create program 'sample.exe' which is an example of         Γòæ
  5579. #Γòæ usage of LR. Sample.exe is a simple interpreter. The syntax of input     Γòæ
  5580. #Γòæ language of it is discribed in file sample.gr.                           Γòæ
  5581. #ΓòÜΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓòÉΓò¥
  5582.  
  5583.  
  5584. # You must set true path to include files of LR - package instead C:\LR\INCLUDE
  5585.  
  5586. CC   = ICC -c -Ss -IC:\LR\INCLUDE
  5587.  
  5588. LINK = LINK386 /W /PM:NOVIO
  5589.  
  5590.  
  5591. # You must set true path to LRP instead C:\LR\BIN
  5592.  
  5593. LRP  = C:\LR\BIN\LRP
  5594.  
  5595. # You must set true path to libraries of LR - package instead C:\LR\LIB\
  5596. SAMPLE.EXE : SAMPLE.OBJ TABLE.OBJ COMMANDS.OBJ
  5597.         $(LINK) SAMPLE.OBJ+TABLE.OBJ+COMMANDS.OBJ, SAMPLE.EXE, NUL,C:\LR\LIB\LR.LIB;
  5598.  
  5599. SAMPLE.OBJ : SAMPLE.C SAMPLE.H
  5600.         $(CC)  SAMPLE.C
  5601.  
  5602. TABLE.OBJ : TABLE.C SAMPLE.H
  5603.         $(CC)  SAMPLE.C
  5604.  
  5605. COMMANDS.OBJ : COMMANDS.C SAMPLE.H SAMPLE.STR
  5606.         $(CC) COMMANDS.C
  5607.  
  5608. SAMPLE.STR : SAMPLE.GR
  5609.         &(LRP) SAMPLE.GR
  5610.  
  5611.  
  5612. ΓòÉΓòÉΓòÉ <hidden> Makefile ΓòÉΓòÉΓòÉ
  5613.  
  5614. #-----------------------------------------------------------------------------
  5615. # MAKEFILE - Make file to make grammars
  5616. #
  5617. # Copyright (C) Transendental Automation, 1993.
  5618. #
  5619. # Type 'make.exe' or 'nmake.exe' to use it or use another tools that can work
  5620. # with make files ( for example IBM WorkFrame/2 ).
  5621. # See notes below for understanding of work of this make file.
  5622. # We hope there is all that you need for compiling your grammars and parsing
  5623. # your text no more no less.
  5624. #-----------------------------------------------------------------------------
  5625.  
  5626.  
  5627. #-----------------------------------------------------------------------------
  5628. #                  PART 1 - define grammar and text
  5629. #
  5630. #            Edit this part when choosing another grammar
  5631. #-----------------------------------------------------------------------------
  5632.  
  5633.  
  5634. #-----------------------------------------------------------------------------
  5635. # Grammar name - if absents, no make at all.
  5636. #
  5637. # This name will be used as name + '.' + extension of input and
  5638. # output files. So,in this case, the GDL file is 'sample.gr'
  5639. # compiled grammar will be named as 'sample.lrs' and parse results
  5640. # will be named as 'sample.prs', this name also will be used in
  5641. # names of structures and constants in 'sample.str' and 'sample.n'
  5642. # files
  5643. #-----------------------------------------------------------------------------
  5644.  
  5645. GR = sample
  5646.  
  5647. #-----------------------------------------------------------------------------
  5648. # Text name - if commented out by #, then only compile grammar
  5649. # You can also set it with any name of file that you want to parse.
  5650. # For example :
  5651. # TEXT = ASD.YYT
  5652. #-----------------------------------------------------------------------------
  5653.  
  5654. TEXT = $(GR).txt
  5655.  
  5656. #-----------------------------------------------------------------------------
  5657. #                  PART 2 - path to LRP compiler/parser
  5658. #
  5659. #                     Edit this part when installing LRP
  5660. # Here must be full path without '\' at end where is placed program 'lrp.exe'
  5661. # that is used to compile grammar and parse input files .
  5662. #-----------------------------------------------------------------------------
  5663.  
  5664. LRP_DIR = C:\LR\BIN
  5665.  
  5666. #-----------------------------------------------------------------------------
  5667. #            PART 3 - making grammar and/or parse text
  5668. #
  5669. #                    Do not edit this part
  5670. #-----------------------------------------------------------------------------
  5671.  
  5672. !CMDSWITCHES +S
  5673. !IFDEF LRP_DIR
  5674.  
  5675. ┬╖SUFFIXES: .gr .lrs .prs
  5676.  
  5677. {.}.gr.lrs:
  5678.         $(LRP_DIR)\LRP.EXE $*.gr
  5679.  
  5680. !IFDEF GR
  5681.  
  5682. !IFDEF TEXT
  5683. $(GR).prs:      $(GR).lrs $(TEXT)
  5684.         $(LRP_DIR)\LRP.EXE $**
  5685. !ENDIF
  5686.  
  5687. $(GR).lrs:      $(GR).gr
  5688.  
  5689.  
  5690. !ENDIF
  5691.  
  5692. !ELSE
  5693. ERR:
  5694.         echo Fatal error U1050: failed to find path to LRP compiler/parser
  5695. !ENDIF
  5696.  
  5697.  
  5698. ΓòÉΓòÉΓòÉ <hidden>  ΓòÉΓòÉΓòÉ
  5699.  
  5700. Here you must replace <<NAME>> with the name of your grammar. E.g. where we had 
  5701. <<NAME>>.LRS we will have SAMPLE.LRS if we compiled Sample grammar.