parser

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	Token   lexer.Token
	Literal string
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"
	"strings"

	"github.com/itsubaki/qasm/pkg/lexer"
	"github.com/itsubaki/qasm/pkg/parser"
)

func main() {
	qasm := `
OPENQASM 3.0;
include "itsubaki/q.qasm";

qubit[2] q;
bit[2]   c;
reset    q;

h  q[0];
cx q[0], q[1];

measure q -> c;
`

	p := parser.New(lexer.New(strings.NewReader(qasm)))
	ast := p.Parse()
	fmt.Println(ast)

	if errs := p.Errors(); len(errs) != 0 {
		for _, err := range errs {
			fmt.Println(err)
		}
	}

}
Output:

OPENQASM 3.0;
include "itsubaki/q.qasm";
qubit[2] q;
bit[2] c;
reset q;
h q[0];
cx q[0], q[1];
measure q -> c;

func New

func New(l *lexer.Lexer) *Parser

func (*Parser) Errors

func (p *Parser) Errors() []string

func (*Parser) Parse

func (p *Parser) Parse() *ast.OpenQASM

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL