Skip to content

Commit

Permalink
Merge pull request #216 from nobu/trailing-spaces
Browse files Browse the repository at this point in the history
[DOC] Strip trailing spaces
  • Loading branch information
nobu committed May 24, 2023
2 parents 2ff42d9 + 111aac9 commit dd4e6c5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions doc/en/Overview-of-racc.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You already know that you define a lexer specification with a rex file. This gen
You have to create a grammar file. The first part of this file, as with the Rex specification file, is a class block. In your project directory, create a file called `test_language.y`. This will be our grammar file. As with the start of our Rex file, we’ll use our class:
``` ruby
class TestLanguage

end
```
Then you will have a grammar block. In Rex, the grammar block is a way to specify the patterns for specific symbols. In Racc, the grammar block describes grammar that can be understood by the parser. As with Rex specification files, we’ll eventually add a rule clause to signify our grammar block. In fact, this clause will mark the start of what are called the “production rules.” To fill in these rules, you have to understand the Racc grammar. So let’s just look at the basics before we try to fill in our nascent grammar file.
Expand Down Expand Up @@ -92,13 +92,13 @@ task :generate => [:lexer, :parser]
So how do we test this? Let’s create a file in our spec directory called `language_parser_spec.rb` and add the following to it:
``` ruby
require './parser.rb'

class TestLanguageParser
describe 'Testing the Parser' do
before do
@evaluator = TestLanguage.new
end

it 'tests for a digit' do
@result = @evaluator.parse("2")
@result.should == 2
Expand All @@ -114,7 +114,7 @@ rule
expression : DIGIT
| DIGIT ADD DIGIT { return val[0] + val[2] }
end

---- inner
def parse(input)
scan_str(input)
Expand All @@ -128,10 +128,10 @@ rule
expression : DIGIT
| DIGIT ADD DIGIT { return val[0] + val[2] }
end

---- header
require_relative 'lexer'

---- inner
def parse(input)
scan_str(input)
Expand Down Expand Up @@ -159,10 +159,10 @@ rule
| DIGIT MULTIPLY DIGIT { return val[0] * val[2] }
| DIGIT DIVIDE DIGIT { return val[0] / val[2] }
end

---- header
require_relative 'lexer'

---- inner
def parse(input)
scan_str(input)
Expand All @@ -183,15 +183,15 @@ macro
SUBTRACT \-
MULTIPLY \*
DIVIDE \/
rule
{BLANK} # no action
{DIGIT} { [:DIGIT, text.to_i] }
{ADD} { [:ADD, text] }
{SUBTRACT} { [:SUBTRACT, text] }
{MULTIPLY} { [:MULTIPLY, text] }
{DIVIDE} { [:DIVIDE, text] }
inner
def tokenize(code)
scan_setup(code)
Expand Down

0 comments on commit dd4e6c5

Please sign in to comment.